import itertools, json, os, sys, time import numpy as np HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) from kstar import kstar, max_cyclic_run, twin_slots LOG = open(os.path.join(HERE, "class.out"), "w") def say(*a): print(*a, flush=True); print(*a, file=LOG, flush=True) # ---- 1. custody gates (served instrument) ----------------------------------- GATES = [("K*(30,{7,11,19})",30,[7,11,19],9),("K*(390,{7,11,19})",390,[7,11,19],8), ("K*(30,{7,11,13,19})",30,[7,11,13,19],10),("K*(30,{7,13,19,23})",30,[7,13,19,23],12), ("K*(330,{7,13,19,23})",330,[7,13,19,23],10)] ok = True for name,P,R,want in GATES: K,x,M,_ = kstar(P,R) good = K==want; ok = ok and good say("GATE %-22s expected %2d observed %2d M=%-9d slots=%-8d %s"%(name,want,K,M,x.size,"PASS" if good else "FAIL")) say("GATES", "ALL PASS" if ok else "FAILURE") if not ok: say("REFUSING TO REPORT: custody gate failure"); LOG.close(); sys.exit(1) def kstar_chunked(P,R,chunk=1<<23): M=P for q in R: M*=q reps=twin_slots(P); nrep=len(reps) total=(M//P)*nrep repsarr=np.asarray(reps,dtype=np.int64) killed=np.zeros(total,dtype=bool) for q in R: for s in range(0,total,chunk): idx=np.arange(s,min(s+chunk,total),dtype=np.int64) x=(idx//nrep)*P+repsarr[idx%nrep] killed[s:s+idx.size] |= (x%q==0)|((x+2)%q==0) return max_cyclic_run(killed), total, M # ---- 2. cross-check #1398's published P=210 rows ---------------------------- A,_,M = kstar_chunked(210,[11,13,17,19,23]); say("XCHK K*(210,{11,13,17,19,23}) =",A,"M",M,"(want 13)") for q in (29,31): C,_,M = kstar_chunked(210,[11,13,17,19,23,q]); say("XCHK q=%d K=%d M=%d marginal=%d (want 18/5)"%(q,C,M,C-A)) # ---- 3. the full P=210 |R|=5 class ------------------------------------------ smalls=[11,13,17,19,23,29] rows=[] for R in itertools.combinations(smalls,5): R=list(R) prodR=1 for q in R: prodR*=q A,sa,Ma = kstar_chunked(210,R) q=2 while True: qq=q if all(qq%d for d in range(2,int(qq**0.5)+1)): if qq not in R and 210%qq!=0: break q+=1 C,sc,Mc = kstar_chunked(210,R+[q]) row=dict(R=R,q=q,A=A,M_A=Ma,C=C,M_C=Mc,marginal=C-A,slots_A=sa,slots_C=sc) rows.append(row) say("CLASS R=%-22s q=%-3d A=%-3d C=%-3d marginal=%-3d M_C=%d"%(R,q,A,C,C-A,Mc)) # ---- 4. P=210 |R|=6 (all six) ---------------------------------------------- K6,s6,M6 = kstar_chunked(210,smalls) say("P210 |R|=6 K*(210,%s) = %d M=%d slots=%d"%(smalls,K6,M6,s6)) json.dump(dict(gates_pass=True,rows=rows,R6=dict(R=smalls,K=K6,M=M6)),open(os.path.join(HERE,"class.json"),"w"),indent=1) say("WROTE class.json") LOG.close() # ---- rest.py (last row + |R|=6) ---- import sys, os, json import numpy as np sys.path.insert(0,'.') from kstar import max_cyclic_run, twin_slots def kstar_chunked(P,R,chunk=1<<22): M=P for q in R: M*=q reps=twin_slots(P); nrep=len(reps); total=(M//P)*nrep repsarr=np.asarray(reps,dtype=np.int64) killed=np.zeros(total,dtype=bool) for q in R: for s in range(0,total,chunk): idx=np.arange(s,min(s+chunk,total),dtype=np.int64) x=(idx//nrep)*P+repsarr[idx%nrep] killed[s:s+idx.size] |= (x%q==0)|((x+2)%q==0) return max_cyclic_run(killed), total, M R=[13,17,19,23,29] A,sA,MA=kstar_chunked(210,R); print("R6sub A=K*(210,%s)=%d M=%d slots=%d"%(R,A,MA,sA),flush=True) C,sC,MC=kstar_chunked(210,[11,13,17,19,23,29]); print("R6 K*(210,all six)=%d M=%d slots=%d"%(C,MC,sC),flush=True) print("last row: R=%s q=11 A=%d C=%d marginal=%d"%(R,A,C,C-A),flush=True) json.dump(dict(R=R,A=A,C=C,marginal=C-A,M_C=MC,R6=C,M6=MC),open('rest.json','w'),indent=1)