"""Job 2916 (route 77 pursuit). Independent stdlib recompute of the two VR normalisations in use on route 77. DEFINITIONS (served natal-cap-38-loudness-driver.js buildLevel/runLevel; fresh1913.py docstring): level x, W = 30*prod(7<=p<=x), N = {r in [0,W): r = 11 or 17 mod 30, r mod p not in {0, p-2} for 7<=p<=x}; scour primes q: x < q, q*q <= W; n_q[c] = #{r in N: r = c mod q}; dev(t,q) = n_q[t mod q] + n_q[(t-2) mod q] - 2|N|/q. VR38(t) = sum_q dev(t,q)^2 / Vbar, Vbar = sum_q (1/q) sum_{a mod q} dev(a,q)^2 (class mean; natal-cap-38, calm-lemma v3) VR1013(t) = sum_q dev(t,q)^2 / Vbin, Vbin = sum_q (2|N|/q)(1 - 2/q) (#1013 / #1537) so VR38 = kappa * VR1013 with kappa = Vbin / Vbar, one constant per level. PRE-REGISTERED FALSIFIERS (written before the first run): F1 VR38(W/2) at @13 != 1.6652 (4 dp) or its rank-from-top over t in [0,W) != 198; F2 VR38(0) != 0.3443 / 0.6231 / 0.5530 at @11/@13/@17 (4 dp); F3 VR1013(0) != 0.080641207 @11 or 0.069410774 @13 (9 dp); F4 W/2 not rank-from-top 0 at @11; F5 the phase mean of VR38 over t in [0,W) differs from 1 by more than it does in natal-cap-38 (0.9990 @11). Stdout is deterministic (no timing); sorted keys.""" import json def primes(n): s = bytearray([1]) * (n + 1); s[0:2] = b'\x00\x00' for i in range(2, int(n ** 0.5) + 1): if s[i]: s[i * i::i] = bytearray(len(s[i * i::i])) return [i for i in range(n + 1) if s[i]] def level(x, sweep): wheel = [p for p in primes(x) if p >= 7]; W = 30 for p in wheel: W *= p N = [r for r in range(W) if r % 30 in (11, 17) and all(r % p not in (0, p - 2) for p in wheel)] Q = [q for q in primes(int(W ** 0.5) + 1) if q > x and q * q <= W] Vbar = Vbin = 0.0; rows = [] for q in Q: n = [0] * q for r in N: n[r % q] += 1 E = 2 * len(N) / q row = [(n[a] + n[(a - 2) % q] - E) ** 2 for a in range(q)] Vbar += sum(row) / q; Vbin += E * (1 - 2 / q); rows.append((q, row)) def ssum(t): return sum(row[t % q] for q, row in rows) h = W // 2; s0, sh = ssum(0), ssum(h) rec = {'W': W, 'N': len(N), 'K': len(Q), 'Vbar': round(Vbar, 6), 'Vbin': round(Vbin, 6), 'kappa': round(Vbin / Vbar, 6), 'VR38_0': round(s0 / Vbar, 6), 'VR38_half': round(sh / Vbar, 6), 'VR1013_0': round(s0 / Vbin, 9), 'VR1013_half': round(sh / Vbin, 9), 'VR38_W_equals_VR38_0': ssum(W) == s0} if sweep: tot = 0.0; above = 0; mx = (-1.0, -1) for t in range(W): v = ssum(t); tot += v if v > sh: above += 1 if v > mx[0]: mx = (v, t) rec.update({'half_rank_from_top': above, 'phase_mean_VR38': round(tot / W / Vbar, 4), 'max_VR38': round(mx[0] / Vbar, 4), 'argmax': mx[1]}) return rec out = {x: level(x, x <= 13) for x in (11, 13, 17)} L11, L13, L17 = out[11], out[13], out[17] checks = { 'F1_VR38_half_13': round(L13['VR38_half'], 4) == 1.6652 and L13['half_rank_from_top'] == 198, 'F2_VR38_0': [round(L['VR38_0'], 4) for L in (L11, L13, L17)] == [0.3443, 0.6231, 0.5530], 'F3_VR1013_0': L11['VR1013_0'] == 0.080641207 and L13['VR1013_0'] == 0.069410774, 'F4_half_top_11': L11['half_rank_from_top'] == 0, 'F5_phase_mean_11': abs(L11['phase_mean_VR38'] - 1) <= 0.0011, } print(json.dumps({'levels': out, 'checks': checks, 'all_pass': all(checks.values())}, indent=1, sort_keys=True))