# t29fold.py - JOB #642: build the gap word of T_29 by the fold of T_23 by q = 29, # per #159 section 0 ("lay q copies of T_x at offsets kW and delete every slot whose # value is 0 or -2 mod q"), and validate it against the record's census. # stdout is the artifact: every line above is a function of the input. The wall time goes to # stderr (fix for solveathome job #648), so stdout reproduces byte for byte on any machine. import numpy as np, hashlib, sys, time W23 = 223092870 q = 29 g23 = np.load("t23-gaps.npy").astype(np.int64) D23 = len(g23) s23 = np.load("t23-slots.npy") # slot values, sorted, mod W23 C = np.concatenate([[0], np.cumsum(g23)]) # C[j] = s23[j] - s23[0], length D23+1 res = (s23 % q).astype(np.int64) t0 = time.time() limit = 0 pieces = [] for k in range(q): t = (-k * (W23 % q)) % q dead = (res == t) | (res == (t - 2) % q) surv = np.flatnonzero(~dead) pieces.append(np.diff(C[surv]).astype(np.int32)) if k == 0: print("copy 0: deleted %d of %d slots, surviving %d" % (dead.sum(), D23, len(surv))) G = np.concatenate(pieces) # seam: last surviving slot of copy k to first surviving slot of copy k+1 seams = [] off = 0 lens = [len(p) for p in pieces] for k in range(q): off += lens[k] seam_gaps = [] starts = np.cumsum([0] + lens) for k in range(q - 1): # last survivor value in copy k, first survivor value in copy k+1 tk = (-k * (W23 % q)) % q deadk = (res == tk) | (res == (tk - 2) % q) skim = int(s23[np.flatnonzero(~deadk)[-1]]) tk1 = (-(k + 1) * (W23 % q)) % q deadk1 = (res == tk1) | (res == (tk1 - 2) % q) fkim = int(s23[np.flatnonzero(~deadk1)[0]]) seam_gaps.append((k + 1) * W23 + fkim - (k * W23 + skim)) # the word is cyclic: insert each seam gap at the right boundary, and one wrap gap at the end Gw = np.insert(G, starts[1:q], np.array(seam_gaps, dtype=np.int32)) last_surv = int(s23[np.flatnonzero(~((res == (-((q - 1) * W23) % q)) | (res == ((-((q - 1) * W23) % q) - 2) % q)))[-1]]) first_surv = int(s23[np.flatnonzero(~((res == 0) | (res == (q - 2))))[0]]) wrapslot = (q - 1) * W23 + last_surv wrap = first_surv + q * W23 - wrapslot Gw = np.append(Gw, np.int32(wrap)) D29 = len(Gw) # measured AFTER the cyclic wrap gap is appended print("D(T_29) = %d record says 214,708,725 -> %s" % (D29, "MATCH" if D29 == 214708725 else "MISMATCH")) print("sum of the word = %d ; q*W23 = %d" % (int(Gw.astype(np.int64).sum()), q * W23)) print("max single gap = %d ; max 2-gap sum = %d (record: G2 = 258)" % (int(Gw.max()), int((Gw[:-1].astype(np.int64) + Gw[1:].astype(np.int64)).max()))) print("all gaps multiples of 6:", bool((Gw % 6 == 0).all())) np.save("t29-gaps.npy", Gw) print("sha256(Gw) =", hashlib.sha256(Gw.tobytes()).hexdigest()) print("%.1f s" % (time.time() - t0), file=sys.stderr)