import scipy.special
s = [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3,
1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 6, 1, 2, 1, 3, 1, 2, 1, 4,
1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3,
1, 2, 1, 7, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5,
1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 6, 1, 2, 1, 3,
1, 2, 1, 4, 1]
r = []
for n in range(20):
result = 1
for k in range(n-1):
result += (scipy.special.binom(n - 1, k) % 2) * r[s[n - k - 1]]
r.append(result)
def binomial_transform(sequence):
n = len(sequence)
result = [0] * n
for i in range(n):
for j in range(i+1):
result[i] += sequence[j] * scipy.special.binom(i, j)
return result
sequence = r
binomial_result = binomial_transform(sequence)
print(binomial_result)
I tried playing with where result began, 0 instead of 1, tried having r initialized with 1 as an element instead of it being empty, tried maybe instead of k in range n-1, k in range n.The code worked perfectly when the list, s, was the oeis sequence A000120, and it produced, as expected, oeis A101911. now that i changed it from A000120 to A001511 it says list index out of range. This has driven me crazy. If i just add another number to the front of s, it compiles without error, but if delete an element, there's an error.