#!/usr/bin/env python3 """Route 56, s = 19 rung: exact K*(19), maxsum_{K*+1}(T_19), rho(19, K*+1), (R). Definitions follow the served producer research/history/staging/ attack-0829n-doubling-bridge.js and the route-56 record: Ghat(s) = G2(s#) = maxsum_1(T_s) (the largest tile gap), maxsum_m(T_s) = largest sum of m consecutive gaps over the level-2s walk, msc(s) = maxsum_{K*(s)+1}(T_s)/Ghat(s), gbar(s) = s# / |T_s|, rho(s,m) = Ghat(s)*msc(s) / (m*gbar(s)) = maxsum_m/(m*gbar), (R): K*(s)+1 <= 8*[Ghat(s)/gbar(s)]/rho(s,K*+1). Output is machine-readable JSON on stdout (stderr carries progress). """ import sys, os, json, time sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import route56_walk as W PS = W.primes_upto(37) def P_of(s): return W.primorial([p for p in PS if p <= s]) def run(s, ns=None, m_extra=()): ns = ns or [p for p in PS if p <= 2 * s and p > s] P = P_of(s) nA = int(W.admissible(P).size) R = 1 for q in ns: R *= q t0 = time.time() K, cols, tot = W.longest_run_columns(P, ns) t_k = time.time() - t0 Ghat = W.walk_gap_maxsum(P, ns, 1) t0 = time.time() m_need = sorted(set([(K or 1) + 1, max(K - 1, 1), max(K, 1)] + list(m_extra))) ms = {m: W.walk_gap_maxsum(P, ns, m) for m in m_need} t_m = time.time() - t0 m = K + 1 mm = ms[m] msc = mm / Ghat gbar = P / nA rho = mm / (m * gbar) rhs = 8.0 * (Ghat / gbar) / rho out = { "s": s, "Q": ns, "P": P, "nA": nA, "R": R, "walk_length": nA * R, "K": K, "Ghat": Ghat, "maxsum_Kplus1": mm, "msc": msc, "gbar": gbar, "rho": rho, "(R)_rhs": rhs, "(R)_holds": (m <= rhs), "margins": {("maxsum_%d" % x): ms[x] for x in m_need}, "seconds": {"K": t_k, "maxsum": t_m}, "complete": cols == nA, } return out if __name__ == "__main__": t00 = time.time() for s in (13, 15, 16, 17, 19): o = run(s) print(json.dumps(o), flush=True) print(json.dumps({"total_seconds": time.time() - t00}), flush=True)