"""Compose early-construction witnesses and compare bounded BFS to the unrestricted oracle."""
from itertools import product
from deux27 import limited
from quatre24 import oracle
from sept28 import path
import json
def study():
    result=[]
    for motif in (0,1):
        blocks=[]
        for length in (5,6):
            for letters in product('ABX',repeat=length):
                if len(set(letters))!=3:continue
                word=''.join(letters)
                if limited(word,motif,1)<limited(word,motif,0):blocks.append(word)
                if len(blocks)==4:break
            if len(blocks)==4:break
        cases=[]
        for a,b in product(blocks,repeat=2):
            word=a+b;ps=[(),(0,) if motif else ()]+[{'A':(0,),'B':(1,),'X':(0,1)}[c] for c in word]
            c=[limited(word,motif,k) for k in range(3)]+[oracle(ps,tuple(range(2,len(ps))),True)]
            assert c[0]==oracle(ps,tuple(range(2,len(ps))),False) and sorted(c,reverse=True)==c
            cases.append(dict(word=word,costs=c))
        first=next((c for c in cases if c['costs'][1]>c['costs'][2]==c['costs'][3]),None)
        trace=path(first['word'],motif,2) if first else []
        if first:assert len(trace)==first['costs'][-1]
        result.append(dict(motif=motif,blocks=blocks,cases=cases,first=first,trace=trace))
    return result
if __name__=='__main__':print(json.dumps(study()))
