A116939 Lexicographically earliest sequence such that each i occurs exactly i+1 times and succeeding terms differ exactly by -1 or +1.
0, 1, 2, 1, 2, 3, 2, 3, 4, 3, 4, 3, 4, 5, 4, 5, 4, 5, 6, 5, 6, 5, 6, 5, 6, 7, 6, 7, 6, 7, 6, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 13, 12, 13
Offset: 0
Keywords
Links
- Reinhard Zumkeller, Table of n, a(n) for n = 0..10000
Programs
-
Haskell
a116939 n = a116939_list !! n a116939_list = 0 : f [0] where f xs@(x : _) = ys ++ f ys where ys = if odd x then (x + 1 : x : map (+ 1) xs) else map (+ 1) xs -- Reinhard Zumkeller, Jun 28 2013
-
Mathematica
a = {0}; Do[AppendTo[a, If[Count[a, # - 1] > # - 1, # + 1, # - 1]] &@ a[[n]], {n, 87}]; a (* Michael De Vlieger, Dec 07 2016 *)
Comments