#!/bin/sh python3 - <<'EOF' S=[(3,6),(5,1),(0,2),(5,0),(0,3),(3,1),(4,1),(1,5)] T=[(5,2),(2,3),(0,1),(2,0),(5,4),(5,6)] def m(p,x,z): a=p[x]; b=p[z]; q=min(a,b) return tuple(q if p[i]==a or p[i]==b else p[i] for i in range(7)) def f(p,E): return set((p[u],p[v]) for u,v in E) def g(A,B): return sorted((x,y,z) for x,y in A for u,z in B if y==u and x!=z and y!=z) r=tuple(range(7)); V={r}; D=[r]; L={r:0}; E=[] while D: p=D.pop(); A=f(p,S); B=f(p,T); C=g(A,B) if not C: E.append(p); continue x,y,z=C[0] for q in (m(p,x,z),m(p,y,z)): if q not in V: V.add(q); L[q]=L[p]+1; D.append(q) for p in sorted(V,key=lambda p:(L[p],p)): print(L[p],p,len(set(p))) print('G',len(V),'K',len(E)) EOF