#! /usr/bin/python3 # Last edited on 2026-09-07 08:31:42 by stolfi # Solves the puzzle posed by #ololololo on Voynich.Ninja on 2026-09-05 # Namely looks for a parag that has the second word repeated two more times, # 6 positions apart. # wp res/starps-gd-wp-par.ivt # wc res/starps-gd-wc-par.ivt # ch res/bencao-fu-ch-par.ivt import sys, re, os, string, glob from sys import stderr as err from math import sqrt, hypot, exp, log, floor, ceil, isfinite, isnan, inf, nan def main(): utype = sys.argv[1] ivt_file = sys.argv[2] rd = open(ivt_file, "r") lines = rd.readlines() for line in lines: trysolve(line, utype) return # ---------------------------------------------------------------------- def trysolve(line, utype): line = line.strip() line = re.sub(r" *[#].*$", "", line) if line == "": return line = re.sub(r"[;][A-Z]", "", line) m = re.fullmatch(r"<([a-z0-9.]+)> *(.*)", line) assert m is not None, f"bad format [[{line = !r}]]" loc = m.group(1) text = m .group(2) text = re.sub(r"[«=»]", "", text) text = re.sub(r"<[%$]>", "", text) if utype == "wc": # Consider commas: text = re.sub(r"[-,]", " ", text) elif utype == "wp": # Ignore commas: text = re.sub(r"[-.]", " ", text) text = re.sub(r"[,]", "", text) elif utype == "ch": # Remove ideographic punctuation: text = re.sub(r"[][;:、,。() ]", "", text) else: assert False, f"bad {utype = !r}" if utype == "ch": toks = [ c for c in text ] else: toks = text.split(); nt = len(toks) if nt < 20: return key = toks[1] occs = [] for i in range(nt): if toks[i] == key and i != 1: occs.append(i) if len(occs) == 2: err.write(f"{loc:<10s} {utype = } {nt = } {key = !r} {occs = }") if occs[1] == nt - 3 and occs[0] == occs[1] - 6: err.write("***") err.write("\n") return # ---------------------------------------------------------------------- main()