OFFSET
0,10
COMMENTS
Let h be the initial term of row n, to get row n+1, remove h and then append h and h+1.
LINKS
Reinhard Zumkeller, Rows n = 0..125 of triangle, flattened
EXAMPLE
. 0: 0
. 1: 0 1
. 2: 1 0 1
. 3: 0 1 1 2
. 4: 1 1 2 0 1
. 5: 1 2 0 1 1 2
. 6: 2 0 1 1 2 1 2
. 7: 0 1 1 2 1 2 2 3
. 8: 1 1 2 1 2 2 3 0 1
. 9: 1 2 1 2 2 3 0 1 1 2
. 10: 2 1 2 2 3 0 1 1 2 1 2
. 11: 1 2 2 3 0 1 1 2 1 2 2 3
. 12: 2 2 3 0 1 1 2 1 2 2 3 1 2
. 13: 2 3 0 1 1 2 1 2 2 3 1 2 2 3
. 14: 3 0 1 1 2 1 2 2 3 1 2 2 3 2 3
. 15: 0 1 1 2 1 2 2 3 1 2 2 3 2 3 3 4 .
MATHEMATICA
T[n_, k_] := DigitCount[n + k + 1, 2, 1] - 1; Table[T[n, k], {n, 0, 12}, {k, 0, n}] // Flatten (* Amiram Eldar, Aug 01 2023 *)
PROG
(Haskell)
a240857 n k = a240857_tabl !! n !! k
a240857_row n = a240857_tabl !! n
a240857_tabl = iterate (\(x:xs) -> xs ++ [x, x + 1]) [0]
(Python)
from math import isqrt
def A240857(n): return (n-((r:=(m:=isqrt(k:=n+1<<1))+(k>m*(m+1)))*(r-3)>>1)).bit_count()-1 # Chai Wah Wu, Nov 11 2024
CROSSREFS
KEYWORD
AUTHOR
Reinhard Zumkeller, Apr 14 2014
STATUS
approved