Python
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:])]
Python
N = 31
d = 1
Python
orbit(N, d)
[31, 47, 71, 107, 161, 242, 121, 182, 91, 137, 206, 103, 155, 233, 350, 175, 263, 395, 593, 890, 445, 668, 334, 167, 251, 377, 566, 283, 425, 638, 319, 479, 719, 1079, 1619, 2429, 3644, 1822, 911, 1367, 2051, 3077, 4616, 2308, 1154, 577, 866, 433, 650, 325, 488, 244, 122, 61, 92, 46, 23, 35, 53, 80, 40, 20, 10, 5, 8, 4, 2, 1]
Python
diffs = orbit_diffs(N, d)
print(diffs)
[16, 24, 36, 54, 81, -121, 61, -91, 46, 69, -103, 52, 78, 117, -175, 88, 132, 198, 297, -445, 223, -334, -167, 84, 126, 189, -283, 142, 213, -319, 160, 240, 360, 540, 810, 1215, -1822, -911, 456, 684, 1026, 1539, -2308, -1154, -577, 289, -433, 217, -325, 163, -244, -122, -61, 31, -46, -23, 12, 18, 27, -40, -20, -10, -5, 3, -4, -2, -1]
## First column `[1] → [2]`:
---
Python
c1 = [x for x in diffs if (x < 0) and (x % 3 == 1)]
print(c1)
x_1 = len(c1)
print(x_1)
[-167, -911, -1154, -122, -23, -20, -5, -2]
8
Python
x_2 = sum([x - (-2) for x in diffs if (x < 0) and (x % 3 == 1)]) / -3
print(x_2)
796.0
## Second column `[1] → [2]`:
---
Python
c2 = [x for x in diffs if (x > 0) and (x % 3 == 1)]
print(c2)
x_3 = len(c2)
print(x_3)
[16, 61, 46, 52, 88, 223, 142, 160, 289, 217, 163, 31]
12
Python
x_4 = sum([x - (1) for x in diffs if (x > 0) and (x % 3 == 1)]) / 3
print(x_4)
492.0
## Third column `[2] → [1]`:
---
Python
c3 = [x for x in diffs if (x < 0) and (x % 3 == 2)]
print(c3)
x_5 = len(c3)
print(x_5)
[-121, -91, -103, -175, -445, -334, -283, -319, -1822, -2308, -577, -433, -325, -244, -61, -46, -40, -10, -4, -1]
20
Python
x_6 = sum([x - (-1) for x in diffs if (x < 0) and (x % 3 == 2)]) / -3
print(x_6)
2574.0
## Fourth column `[2] → [2]`:
---
Python
x_7 = sum([x - (0) for x in diffs if (x > 0) and (x % 3 == 0)]) / 3
print(x_7)
2876.0
Python
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))
-30.0
-30
Python
print(f"-2*({x_1}) - 3*({x_2}) + ({x_3}) + 3*({x_4}) - ({x_5}) - 3*({x_6}) + 3*({x_7}) = {check}")
-2*(8) - 3*(796.0) + (12) + 3*(492.0) - (20) - 3*(2574.0) + 3*(2876.0) = -30.0
Python
print(f"V = ({x_1}, {x_2}, {x_3}, {x_4}, {x_5}, {x_6}, {x_7})")
line 1, in <module>
    print(f"V = ({x_1}, {x_2}, {x_3}, {x_4}, {x_5}, {x_6}, {x_7})")
                  ^^^
NameError: name 'x_1' is not defined