Given a positive integer $n$, I want to find the number of sequences starting with $1$ and ending with $n$, such that every two adjacent elements $i,j$ satisfy $j\oplus i<j$ and $j>i$ ($\oplus$ is bitwise XOR).
I tried to solve this problem through brute force and got some results with the following code:
ans = [0] * 33
ans[1] = 1
def f(n):
for i in range(1, n + 1):
for j in range(1, i):
if ans[j] and i ^ j < i:
ans[i] += ans[j]
f(32)
for i, j in enumerate(ans):
print(i, j)
The results from 0 to 32 are like this, and it seems to have some kind of regularity, but I can't explain it.
[0, 1, 0, 1, 0, 1, 2, 5, 0, 1, 2, 5, 16, 33, 66, 133, 0, 1, 2, 5, 16, 33, 66, 133, 512, 1025, 2050, 4101, 8208, 16417, 32834, 65669, 0]
Could you please tell if there is any way to solve it. Thanks!
In binary
Can you spot a pattern?