def col(n, d): return (3*n + d) >> 1 if n % 2 == 1 else (n >> 1)
def orbit(n, d=1):
visited = set()
sequence = [n]
current = n
while True:
current = col(current, d)
if current in visited:
break
sequence.append(current)
visited.add(current)
return sequence
def orbit_diffs(n, d=1):
sequence = orbit(n, d)
return [b - a for a, b in zip(sequence, sequence[1:])]N = 31 d = 1
orbit(N, d)
diffs = orbit_diffs(N, d) print(diffs)
## First column `[1] → [2]`: ---
c1 = [x for x in diffs if (x < 0) and (x % 3 == 1)] print(c1) x_1 = len(c1) print(x_1)
x_2 = sum([x - (-2) for x in diffs if (x < 0) and (x % 3 == 1)]) / -3 print(x_2)
## Second column `[1] → [2]`: ---
c2 = [x for x in diffs if (x > 0) and (x % 3 == 1)] print(c2) x_3 = len(c2) print(x_3)
x_4 = sum([x - (1) for x in diffs if (x > 0) and (x % 3 == 1)]) / 3 print(x_4)
## Third column `[2] → [1]`: ---
c3 = [x for x in diffs if (x < 0) and (x % 3 == 2)] print(c3) x_5 = len(c3) print(x_5)
x_6 = sum([x - (-1) for x in diffs if (x < 0) and (x % 3 == 2)]) / -3 print(x_6)
## Fourth column `[2] → [2]`: ---
x_7 = sum([x - (0) for x in diffs if (x > 0) and (x % 3 == 0)]) / 3 print(x_7)
check = -2*x_1 - 3*x_2 + x_3 + 3*x_4 - x_5 - 3*x_6 + 3*x_7 print(check) print(sum(diffs))
print(f"-2*({x_1}) - 3*({x_2}) + ({x_3}) + 3*({x_4}) - ({x_5}) - 3*({x_6}) + 3*({x_7}) = {check}")print(f"V = ({x_1}, {x_2}, {x_3}, {x_4}, {x_5}, {x_6}, {x_7})")