OFFSET
0,4
COMMENTS
LINKS
John Tyler Rascoe, Rows n = 0..12, flattened
FORMULA
T(n,k) = - Sum_{i=0..n-1} (i+1)*(-1)^b[i] where the binary expansion of k is k = Sum_{i=0..n-1} b[i]*2^i. - Kevin Ryde, Nov 14 2023
EXAMPLE
Triangle begins:
k=0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
n=0: 0;
n=1: -1, 1;
n=2: -3, -1, 1, 3;
n=3: -6, -4, -2, 0, 0, 2, 4, 6;
n=4: -10, -8, -6, -4, -4, -2, 0, 2, -2, 0, 2, 4, 4, 6, 8, 10;
...
The binary tree starts with root 0 in row n = 0. For rows n < 2, k = 0.
In row n = 3, the parent node -3 has left child -6 = 2*(-3) - (-1) - 1.
The tree begins:
row
[n]
[0] ______0______
/ \
[1] __-1__ __1__
/ \ / \
[2] -3 -1 1 3
/ \ / \ / \ / \
[3] -6 -4 -2 0 0 2 4 6
.
PROG
(Python)
def A365968(n, k):
b, x = bin(k)[2:].zfill(n), 0
for i in range(0, n):
x += (-1)**(int(b[n-(i+1)])+1)*(i+1)
return(x) # John Tyler Rascoe, Nov 12 2023
(PARI) T(n, k) = sum(i=0, n-1, if(bittest(k, i), i+1, -(i+1))); \\ Kevin Ryde, Nov 14 2023
CROSSREFS
KEYWORD
AUTHOR
John Tyler Rascoe, Sep 23 2023
STATUS
approved