A108730 Triangle read by rows: row n gives the list of the number of zeros following each 1 in the binary representation of n.
0, 1, 0, 0, 2, 1, 0, 0, 1, 0, 0, 0, 3, 2, 0, 1, 1, 1, 0, 0, 0, 2, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 4, 3, 0, 2, 1, 2, 0, 0, 1, 2, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 3, 0, 2, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 5, 4, 0, 3, 1, 3, 0, 0, 2, 2, 2, 1, 0, 2, 0, 1, 2, 0, 0, 0, 1, 3, 1, 2, 0
Offset: 1
Examples
Triangle begins: 0 1 0,0 2 1,0 0,1 0,0,0 3 For example, 25 = 11001_2; following the 1's are 0, 2 and 0 zeros, so row 25 is 0, 2, 0.
Links
- Franklin T. Adams-Watters, Table of n, a(n) for n = 1..5120 (through 10 bit numbers)
Crossrefs
Programs
-
Haskell
import Data.List (unfoldr, group) a108730 n k = a108730_tabf !! (n-1) !! (k-1) a108730_row = f . group . reverse . unfoldr (\x -> if x == 0 then Nothing else Just $ swap $ divMod x 2) where f [] = [] f [os] = replicate (length os) 0 f (os:zs:dss) = replicate (length os - 1) 0 ++ [length zs] ++ f dss a108730_tabf = map a108730_row [1..] a108730_list = concat a108730_tabf -- Reinhard Zumkeller, Feb 26 2012
-
Mathematica
row[n_] := (id = IntegerDigits[n, 2]; sp = Split[id]; f[run_List] := If[First[run] == 0, run, Sequence @@ Table[{}, {Length[run] - 1}]]; len = Length /@ f /@ sp; If[Last[id] == 0, len, Append[len, 0]]); Flatten[ Table[row[n], {n, 1, 41}]] (* Jean-François Alcover, Jul 13 2012 *)
-
PARI
row(n)=my(v=vector(hammingweight(n)),t=n); for(i=0,#v-1,v[#v-i] = valuation(t,2); t>>=v[#v-i]+1); v \\ Charles R Greathouse IV, Sep 14 2015
Extensions
Edited by Franklin T. Adams-Watters, Nov 06 2006
Comments