#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Job #1410 support: pin the counting convention and one mismatch, by literal brute force over the slot list (no regex, no automaton). Prints, for each fold: the longest killed window (number of consecutive SLOTS all in {a,a+2} for some translate a) and the longest chain of gaps+1, plus the witness window position, so the two readings of "L" are separated by measurement.""" import importlib.util, sys from pathlib import Path here = Path(__file__).resolve().parent spec = importlib.util.spec_from_file_location("dc", here / "direct-capacity.py") dc = importlib.util.module_from_spec(spec) spec.loader.exec_module(dc) def brute_window(res, p): """Longest cyclic run of consecutive slots whose residues all lie in {a, a+2} for some a. Returns (slots_in_window, best_a, start_index) by direct scan.""" n = len(res) r = [v % p for v in res] best, best_a, best_i = 0, None, None for a in range(p): a2 = (a + 2) % p dead = [1 if (r[i] == a or r[i] == a2) else 0 for i in range(n)] if not any(dead): continue # longest cyclic run of 1s starting at each index, capped at n i = 0 start = None for k in range(2 * n): j = k % n if dead[j]: if start is None or k - start >= n: start = k L = k - start + 1 if L > best and L <= n: best, best_a, best_i = L, a, start % n else: start = None return best, best_a, best_i def main(): diag = [(7, 11, 2), (11, 13, 1), (13, 17, 2), (17, 19, 2), (19, 23, 2), (23, 29, 3)] print("fold p window_slots gapchain+1 brief_diagonal witness_start") for x, p, want in diag: res, M, chain = dc.build_tile(x) g = dc.gaps_of(res, M) m, a, i = brute_window(res, p) auto = dc.row_by_automaton(g, [p])[p] print(f"T_{x:<3} {p:<3} {m:>12} {auto:>11} {want:>15} a={a} start={i}") # the one mismatch between the regex instrument and the automaton: T_19, p=37 x, p = 19, 37 res, M, chain = dc.build_tile(x) g = dc.gaps_of(res, M) m, a, i = brute_window(res, p) auto = dc.row_by_automaton(g, [p])[p] regex = dc.direct_row(res, [p])[p] print(f"\nmismatch case T_{x}, p={p}: brute window_slots={m} (a={a}, start={i}); " f"automaton={auto}; regex-instrument run={regex['run']} L_field={regex['L']}") if i is not None: n = len(res) win = [res[(i + k) % n] for k in range(m)] print(" witness slots mod x#:", win) print(" their residues mod p:", [v % p for v in win]) if __name__ == "__main__": sys.exit(main())