Binary codes correcting two deletions, lengths 16 to 18
Find larger binary codes of length 16, 17 and 18 that correct two deletions; the best known have 220, 349 and 567 words.
Bring the checks and the files they read, from shoal-catalog cfb093e61504
Browse files+3 −0 .gitignore added View file
| @@ -0,0 +1,3 @@ | ||
| 1 | +__pycache__/ | |
| 2 | +*.pyc | |
| 3 | +.ipynb_checkpoints/ | |
+46 −0 checks/README.md added View file
| @@ -0,0 +1,46 @@ | ||
| 1 | +# The checks and how to submit | |
| 2 | + | |
| 3 | +The checks run the judge in `checks/judge/` at the project's approved version, with your pushed commit as input, so a | |
| 4 | +route cannot change how it is judged. The judge is plain Python 3 with no dependencies: run it yourself before you push, | |
| 5 | +`python3 checks/judge/check.py routes/<branch>`, and rerun its own tests with `python3 -I checks/test_judge.py`. | |
| 6 | + | |
| 7 | +## Files | |
| 8 | + | |
| 9 | +- `constructions/n16.json`: the record code of 220 words (EinsteinArena submission #2622). | |
| 10 | +- `constructions/n17.json`, `constructions/n18.json`: codes of 316 and 525 words from a lexicographic greedy computed | |
| 11 | + for this project (every word in increasing order, kept when it shares no descendant with a word kept before). They | |
| 12 | + are starting points, not records. | |
| 13 | +- `tools/check_format.py`: checks that files follow the submission format; it does not check the descendants. | |
| 14 | + | |
| 15 | +## Submission format | |
| 16 | + | |
| 17 | +- **Files.** A candidate is a file whose name ends in `.json`, anywhere in your route's folder `routes/<branch>/`, whose | |
| 18 | + content is a JSON object with the keys `"n"` and `"words"`; other keys are ignored. A `.json` file whose content is | |
| 19 | + not an object with `"words"` is not a candidate and is ignored, but a `.json` file that is not valid JSON fails the | |
| 20 | + check. Keep each file under 1 MB. | |
| 21 | +- **`"n"`**: a JSON integer, 16, 17 or 18. | |
| 22 | +- **`"words"`**: a nonempty list of distinct strings, each of exactly `n` characters `0` and `1`, as EinsteinArena's | |
| 23 | + `"words"`. | |
| 24 | +- **Value.** The number of words, when no two words share a descendant. A candidate in which two words share one is | |
| 25 | + not a code: `verify` fails and names the two words and their common descendant. | |
| 26 | +- **Score.** For each length, the route's largest code divided by the record, where a length counts as its starting | |
| 27 | + code (220, 316 or 525 words) when the route has nothing larger. The score is the mean of the three ratios, higher is | |
| 28 | + better: `main` starts at $26680/28269\approx 0.9438$, and holding all three records scores 1. `verify` writes it to | |
| 29 | + `metrics.json` as `score` (a float) and `score_exact` (the exact fraction), with each length's largest code in | |
| 30 | + `subtasks` and the lengths above their records in `new_records`. | |
| 31 | + | |
| 32 | +## How to check and submit | |
| 33 | + | |
| 34 | +- Check a folder before you push: `python3 tools/check_format.py routes/<branch>`. | |
| 35 | +- Push your work to your route. Two checks run on every push: | |
| 36 | + - **`verify`** checks every candidate in your route's folder exactly. It prints one line per candidate, | |
| 37 | + `<length>: <size> words (<file>), <difference> against the record`, ending `; a new record` when the code is larger | |
| 38 | + than the record, then the score and the new records. It fails if a `.json` file is unreadable or a candidate is | |
| 39 | + malformed or not a code; a route with no candidate passes with "no candidates to check". On `main` it also reads | |
| 40 | + `constructions/`. | |
| 41 | + - **`improves`** only informs: it never blocks a merge. For each length your route has a code for, it prints your | |
| 42 | + largest code against the largest `main` holds (in `constructions/` and `routes/`) and says whether it is a new | |
| 43 | + record. It passes when, for some length, your code has more words than `main`'s. | |
| 44 | +- Open a pull request into `main` when `improves` passes: the site's maintainer takes improvements in. Any other | |
| 45 | + result, such as a method that others can reuse or a negative result, is judged by review: say in your route's notes | |
| 46 | + exactly what you claim and how to check it. | |
+8 −0 checks/improves.sbatch added View file
| @@ -0,0 +1,8 @@ | ||
| 1 | +#!/bin/bash | |
| 2 | +#SBATCH --job-name=improves | |
| 3 | +#SBATCH --time=5:00 | |
| 4 | +#SBATCH --cpus-per-task=1 | |
| 5 | +# Informs, never blocks a merge: for each length the pushed route has a code for, its largest code against the largest | |
| 6 | +# the default branch holds and against the public record; passes when some length improves on the default branch. The | |
| 7 | +# judge is checks/judge/, at the approved version; its working directory is the default branch as approved. | |
| 8 | +python3 checks/judge/improves.py "$SS_INPUT/$SS_ROUTE_DIR" "$PWD" | |
+33 −0 checks/judge/check.py added View file
| @@ -0,0 +1,33 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""The project's judge (the check `verify`): every candidate (*.json with "words") in the route's folder, checked | |
| 3 | +exactly by codes.py; on the default branch, whose route folder is routes/, constructions/ too. Both files are in checks/judge/, which a check runs at the project's approved version. One line per candidate, then the score and the new records; | |
| 4 | +metrics.json in the working directory gets the score (a float and its exact value), each length's largest code and the | |
| 5 | +lengths above their records. Fails when a candidate is unreadable, malformed or not a code correcting two deletions.""" | |
| 6 | +import json | |
| 7 | +import os | |
| 8 | +import pathlib | |
| 9 | +import sys | |
| 10 | + | |
| 11 | +from codes import INSTANCES, RECORD, best_of, is_record, scan, score | |
| 12 | + | |
| 13 | +root = pathlib.Path(sys.argv[1]) | |
| 14 | +roots = [root] + ([root.parent / "constructions"] if os.environ.get("SS_ROUTE_DIR") == "routes" else []) | |
| 15 | +found, bad = [], 0 | |
| 16 | +for name, instance, size in scan(roots): | |
| 17 | + if instance is None: | |
| 18 | + print(f"{name}: {size}") | |
| 19 | + bad += 1 | |
| 20 | + continue | |
| 21 | + found.append((name, instance, size)) | |
| 22 | + d = size - RECORD[instance] | |
| 23 | + print(f"{instance}: {size} words ({name}), {d:+d} against the record{'; a new record' if is_record(instance, size) else ''}") | |
| 24 | +best = best_of(found) | |
| 25 | +if best: | |
| 26 | + s = score({k: v for k, (v, _) in best.items()}) | |
| 27 | + new = [k for k in INSTANCES if k in best and is_record(k, best[k][0])] | |
| 28 | + metrics = {"score": float(s), "score_exact": str(s), "subtasks": {k: best[k][0] for k in INSTANCES if k in best}, "new_records": new} | |
| 29 | + pathlib.Path("metrics.json").write_text(json.dumps(metrics) + "\n") | |
| 30 | + print(f"score {float(s):.6f}; " + (f"new records: {', '.join(new)}" if new else "no new record")) | |
| 31 | +else: | |
| 32 | + print(f"no valid candidates: {bad} failed" if bad else "no candidates to check") | |
| 33 | +sys.exit(1 if bad else 0) | |
+95 −0 checks/judge/codes.py added View file
| @@ -0,0 +1,95 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""Exact check of binary codes that correct two deletions, for the lengths n = 16, 17 and 18. | |
| 3 | + | |
| 4 | +A candidate is a JSON object {"n": n, "words": ["0110...", ...]}: distinct strings of n binary digits. It corrects two | |
| 5 | +deletions when no two of its words share a descendant, a string of length n - 2 obtained by deleting two positions of a | |
| 6 | +word. Its value is the number of words. The check computes every descendant of every word, as EinsteinArena's verifier | |
| 7 | +does: exact strings, no floating-point number. Python >= 3.9, standard library only. | |
| 8 | +""" | |
| 9 | +import json | |
| 10 | +from fractions import Fraction | |
| 11 | +from itertools import combinations | |
| 12 | +from pathlib import Path | |
| 13 | + | |
| 14 | +SIZES = (16, 17, 18) | |
| 15 | +INSTANCES = tuple(f"n{n}" for n in SIZES) | |
| 16 | +# instance -> the public record: the largest code reported, who found it, when, and where it is listed | |
| 17 | +RECORDS = json.loads(Path(__file__).with_name("records.json").read_text()) | |
| 18 | +RECORD = {k: v["value"] for k, v in RECORDS.items()} | |
| 19 | +# The sizes of the codes in constructions/ that the project starts from: the record for n = 16, greedy codes otherwise. | |
| 20 | +START = {"n16": 220, "n17": 316, "n18": 525} | |
| 21 | + | |
| 22 | + | |
| 23 | +class CandidateError(ValueError): | |
| 24 | + pass | |
| 25 | + | |
| 26 | + | |
| 27 | +def descendants(w: str) -> set[str]: | |
| 28 | + return {w[:i] + w[i + 1:j] + w[j + 1:] for i, j in combinations(range(len(w)), 2)} | |
| 29 | + | |
| 30 | + | |
| 31 | +def words(candidate: dict) -> tuple[str, list[str]]: | |
| 32 | + """The candidate's instance ("n17") and its words; raises CandidateError when it is malformed or not a code that | |
| 33 | + corrects two deletions.""" | |
| 34 | + n, ws = candidate.get("n"), candidate.get("words") | |
| 35 | + if type(n) is not int or n not in SIZES: | |
| 36 | + raise CandidateError('"n" must be one of the integers 16, 17, 18') | |
| 37 | + if not isinstance(ws, list) or not ws: | |
| 38 | + raise CandidateError('"words" must be a nonempty list') | |
| 39 | + for w in ws: | |
| 40 | + if not isinstance(w, str) or len(w) != n or not set(w) <= {"0", "1"}: | |
| 41 | + raise CandidateError(f"every word must be a string of {n} binary digits, not {str(w)[:40]!r}") | |
| 42 | + if len(set(ws)) != len(ws): | |
| 43 | + raise CandidateError("the words must be distinct") | |
| 44 | + seen: dict[str, str] = {} | |
| 45 | + for w in ws: | |
| 46 | + for d in descendants(w): | |
| 47 | + other = seen.setdefault(d, w) | |
| 48 | + if other != w: | |
| 49 | + raise CandidateError(f"{other} and {w} share the descendant {d}") | |
| 50 | + return f"n{n}", ws | |
| 51 | + | |
| 52 | + | |
| 53 | +def is_record(instance: str, size: int) -> bool: | |
| 54 | + return size > RECORD[instance] | |
| 55 | + | |
| 56 | + | |
| 57 | +def score(best: dict[str, int]) -> Fraction: | |
| 58 | + """The mean over the three lengths of size / record, where a length counts as its starting code when the route has | |
| 59 | + nothing larger.""" | |
| 60 | + return sum(Fraction(max(best.get(k, 0), START[k]), RECORD[k]) for k in INSTANCES) / len(INSTANCES) | |
| 61 | + | |
| 62 | + | |
| 63 | +def scan(roots): | |
| 64 | + """(file, instance, size) for each candidate (*.json with "words") under these folders, in order. For a file that | |
| 65 | + is unreadable or malformed, instance is None and size says why; other JSON files are not candidates.""" | |
| 66 | + for root in roots: | |
| 67 | + for path in sorted(root.rglob("*.json")) if root.exists() else []: | |
| 68 | + name = str(path.relative_to(root.parent)) | |
| 69 | + try: | |
| 70 | + candidate = json.loads(path.read_text()) | |
| 71 | + except Exception as exc: | |
| 72 | + yield name, None, f"unreadable ({exc})" | |
| 73 | + continue | |
| 74 | + if not isinstance(candidate, dict) or "words" not in candidate: | |
| 75 | + continue | |
| 76 | + try: | |
| 77 | + instance, ws = words(candidate) | |
| 78 | + except CandidateError as exc: | |
| 79 | + yield name, None, f"not a code correcting two deletions: {exc}" | |
| 80 | + continue | |
| 81 | + yield name, instance, len(ws) | |
| 82 | + | |
| 83 | + | |
| 84 | +def best_of(found) -> dict[str, tuple[int, str]]: | |
| 85 | + """Each instance's largest code among scanned candidates, with the file that holds it.""" | |
| 86 | + best = {} | |
| 87 | + for name, instance, size in found: | |
| 88 | + if instance and (instance not in best or size > best[instance][0]): | |
| 89 | + best[instance] = (size, name) | |
| 90 | + return best | |
| 91 | + | |
| 92 | + | |
| 93 | +def card(instance: str) -> str: | |
| 94 | + r = RECORDS[instance] | |
| 95 | + return f"{r['value']} ({r['by']}, {r['date']})" | |
+37 −0 checks/judge/improves.py added View file
| @@ -0,0 +1,37 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""The project's second judge (the check `improves`, which informs and does not gate a merge): for each length the | |
| 3 | +pushed route has a code for, its largest code against the largest the default branch holds (constructions/ and routes/ | |
| 4 | +of the check's own checkout, the approved version) and against the public record. A length improves when the route's | |
| 5 | +code has at least one word more; it is a new record when it has at least one word more than the record. Passes when | |
| 6 | +some length improves. On the default branch itself it reports what it holds and passes.""" | |
| 7 | +import os | |
| 8 | +import pathlib | |
| 9 | +import sys | |
| 10 | + | |
| 11 | +from codes import INSTANCES, best_of, card, is_record, scan | |
| 12 | + | |
| 13 | +main_dir = pathlib.Path(sys.argv[2]) | |
| 14 | +held = best_of(scan([main_dir / "constructions", main_dir / "routes"])) | |
| 15 | +if os.environ.get("SS_ROUTE_DIR", "") == "routes": | |
| 16 | + new = [k for k in INSTANCES if k in held and is_record(k, held[k][0])] | |
| 17 | + holds = ", ".join(f"{k}: {held[k][0]}" for k in INSTANCES if k in held) or "no code" | |
| 18 | + print(f"the default branch holds {holds}; " + (f"new records: {', '.join(new)}" if new else "no new record")) | |
| 19 | + sys.exit(0) | |
| 20 | +route = best_of(scan([pathlib.Path(sys.argv[1])])) | |
| 21 | +if not route: | |
| 22 | + print("no code in this route to compare") | |
| 23 | + sys.exit(1) | |
| 24 | +better, new = [], [] | |
| 25 | +for k in (k for k in INSTANCES if k in route): | |
| 26 | + size, name = route[k] | |
| 27 | + h = held.get(k) | |
| 28 | + up = h is None or size > h[0] | |
| 29 | + better += [k] if up else [] | |
| 30 | + new += [k] if is_record(k, size) else [] | |
| 31 | + against = f"the default branch's {h[0]}, {size - h[0]:+d}" if h else "nothing on the default branch" | |
| 32 | + print(f"{k}: {size} words ({name}) against {against}{': improves' if up else ''}; " | |
| 33 | + + (f"a new record, above {card(k)}" if is_record(k, size) else f"the record is {card(k)}")) | |
| 34 | +if not better: | |
| 35 | + print("no improvement on the default branch") | |
| 36 | + sys.exit(1) | |
| 37 | +print(f"improves on the default branch: {', '.join(better)}; " + (f"new records: {', '.join(new)}" if new else "no new record")) | |
+20 −0 checks/judge/records.json added View file
| @@ -0,0 +1,20 @@ | ||
| 1 | +{ | |
| 2 | + "n16": { | |
| 3 | + "value": 220, | |
| 4 | + "by": "nightshift-dc16, EinsteinArena submission #2622", | |
| 5 | + "date": "2026-10-15", | |
| 6 | + "url": "https://einsteinarena.com/problems/two-deletion-code-16" | |
| 7 | + }, | |
| 8 | + "n17": { | |
| 9 | + "value": 349, | |
| 10 | + "by": "Weindel and Heckel, ReduMIS (arXiv:2504.00613v2)", | |
| 11 | + "date": "2026-06-05", | |
| 12 | + "url": "https://arxiv.org/abs/2504.00613v2" | |
| 13 | + }, | |
| 14 | + "n18": { | |
| 15 | + "value": 567, | |
| 16 | + "by": "Weindel and Heckel, ReduMIS (arXiv:2504.00613v2)", | |
| 17 | + "date": "2026-06-05", | |
| 18 | + "url": "https://arxiv.org/abs/2504.00613v2" | |
| 19 | + } | |
| 20 | +} | |
+188 −0 checks/test_judge.py added View file
| @@ -0,0 +1,188 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""Tests of the judge, the format checker and the starting codes. Run: python3 -I checks/test_judge.py""" | |
| 3 | +import json | |
| 4 | +import os | |
| 5 | +import shutil | |
| 6 | +import subprocess | |
| 7 | +import sys | |
| 8 | +import tempfile | |
| 9 | +from fractions import Fraction | |
| 10 | +from itertools import combinations | |
| 11 | +from pathlib import Path | |
| 12 | + | |
| 13 | +PKG = Path(__file__).resolve().parent.parent | |
| 14 | +JUDGE, REPO = PKG / "checks" / "judge", PKG | |
| 15 | +sys.dont_write_bytecode = True | |
| 16 | +sys.path.insert(0, str(JUDGE)) | |
| 17 | +from codes import INSTANCES, RECORD, START # noqa: E402 | |
| 18 | + | |
| 19 | + | |
| 20 | +def run(script, *args, cwd, route_dir="routes/x"): | |
| 21 | + # as the check runs it (python3 checks/judge/check.py), without the environment's PYTHON* variables or user site | |
| 22 | + env = {"PATH": os.environ.get("PATH", "/usr/bin:/bin"), "SS_ROUTE_DIR": route_dir} | |
| 23 | + p = subprocess.run([sys.executable, "-E", "-s", "-B", str(script), *map(str, args)], cwd=cwd, capture_output=True, text=True, env=env, timeout=120) | |
| 24 | + return p.returncode, p.stdout, p.stderr | |
| 25 | + | |
| 26 | + | |
| 27 | +def is_code(words): | |
| 28 | + """Independent of the judge: every pair of words, every pair of deleted positions in each.""" | |
| 29 | + n = len(words[0]) | |
| 30 | + sub = lambda w, i, j: w[:i] + w[i + 1:j] + w[j + 1:] | |
| 31 | + D = [{sub(w, i, j) for i, j in combinations(range(n), 2)} for w in words] | |
| 32 | + return len(set(words)) == len(words) and all(D[a].isdisjoint(D[b]) for a, b in combinations(range(len(words)), 2)) | |
| 33 | + | |
| 34 | + | |
| 35 | +def start(k): | |
| 36 | + return json.loads((REPO / "constructions" / f"{k}.json").read_text()) | |
| 37 | + | |
| 38 | + | |
| 39 | +def write(folder, files): | |
| 40 | + for name, content in files.items(): | |
| 41 | + path = folder / name | |
| 42 | + path.parent.mkdir(parents=True, exist_ok=True) | |
| 43 | + if isinstance(content, bytes): | |
| 44 | + path.write_bytes(content) | |
| 45 | + else: | |
| 46 | + path.write_text(content if isinstance(content, str) else json.dumps(content)) | |
| 47 | + | |
| 48 | + | |
| 49 | +def check(files, judge=JUDGE, route_dir="routes/x", main=None): | |
| 50 | + """Runs verify on a route folder holding these files (and main's constructions/ when given); returns (exit code, | |
| 51 | + stdout, stderr, metrics or None).""" | |
| 52 | + with tempfile.TemporaryDirectory() as tmp: | |
| 53 | + folder = Path(tmp, *route_dir.split("/")) | |
| 54 | + folder.mkdir(parents=True) | |
| 55 | + write(folder, files) | |
| 56 | + if main: | |
| 57 | + write(Path(tmp, "constructions"), main) | |
| 58 | + code, out, err = run(judge / "check.py", folder, cwd=tmp, route_dir=route_dir) | |
| 59 | + metrics = Path(tmp, "metrics.json") | |
| 60 | + return code, out, err, json.loads(metrics.read_text()) if metrics.exists() else None | |
| 61 | + | |
| 62 | + | |
| 63 | +def judge_with(records, tmp): | |
| 64 | + """A copy of the judge whose records are changed: {instance: size}.""" | |
| 65 | + out = Path(tmp, "judge") | |
| 66 | + shutil.copytree(JUDGE, out) | |
| 67 | + table = json.loads((JUDGE / "records.json").read_text()) | |
| 68 | + for k, v in records.items(): | |
| 69 | + table[k]["value"] = v | |
| 70 | + (out / "records.json").write_text(json.dumps(table)) | |
| 71 | + return out | |
| 72 | + | |
| 73 | + | |
| 74 | +def test_starts(): | |
| 75 | + assert RECORD == {"n16": 220, "n17": 349, "n18": 567} | |
| 76 | + for k in INSTANCES: | |
| 77 | + c = start(k) | |
| 78 | + assert f"n{c['n']}" == k and len(c["words"]) == START[k] and all(len(w) == c["n"] for w in c["words"]), k | |
| 79 | + assert is_code(c["words"]), k | |
| 80 | + code, out, err, m = check({}, route_dir="routes", main={f"{k}.json": start(k) for k in INSTANCES}) | |
| 81 | + assert code == 0 and not err, out + err | |
| 82 | + s = (Fraction(220, 220) + Fraction(316, 349) + Fraction(525, 567)) / 3 | |
| 83 | + assert m == {"score": float(s), "score_exact": "26680/28269", "subtasks": {"n16": 220, "n17": 316, "n18": 525}, "new_records": []}, m | |
| 84 | + assert str(s) == "26680/28269" | |
| 85 | + assert "n16: 220 words (constructions/n16.json), +0 against the record\n" in out, out | |
| 86 | + assert out.strip().endswith("score 0.943790; no new record"), out | |
| 87 | + | |
| 88 | + | |
| 89 | +def test_score_and_new_records(): | |
| 90 | + small = {"n": 17, "words": start("n17")["words"][:10]} | |
| 91 | + with tempfile.TemporaryDirectory() as tmp: | |
| 92 | + code, out, err, m = check({"a.json": start("n18"), "small.json": small}, judge=judge_with({"n18": 500}, tmp)) | |
| 93 | + assert code == 0 and not err, out + err | |
| 94 | + s = (1 + Fraction(316, 349) + Fraction(525, 500)) / 3 # n16 and n17 count as their starts | |
| 95 | + assert m["score_exact"] == str(s) and m["subtasks"] == {"n17": 10, "n18": 525} and m["new_records"] == ["n18"], m | |
| 96 | + assert "n18: 525 words (x/a.json), +25 against the record; a new record\n" in out, out | |
| 97 | + assert out.strip().endswith("; new records: n18"), out | |
| 98 | + | |
| 99 | + | |
| 100 | +def test_codes_that_share_a_descendant_fail(): | |
| 101 | + clash = {"n": 16, "words": ["0" * 16, "0" * 15 + "1"]} # deleting the 1 and a 0 gives fourteen 0s, as from 0...0 | |
| 102 | + code, out, err, m = check({"clash.json": clash}) | |
| 103 | + assert code == 1 and "share the descendant 00000000000000" in out and not err and m is None, out | |
| 104 | + worse = {"n": 18, "words": start("n18")["words"] + ["1" * 17 + "0"]} | |
| 105 | + assert not is_code(worse["words"]) | |
| 106 | + code, out, err, m = check({"worse.json": worse}) | |
| 107 | + assert code == 1 and "not a code correcting two deletions" in out, out | |
| 108 | + | |
| 109 | + | |
| 110 | +def test_invalid_candidates_fail_cleanly(): | |
| 111 | + good = start("n16") | |
| 112 | + w = good["words"] | |
| 113 | + cases = { | |
| 114 | + "length": ({**good, "words": w[:-1] + [w[-1] + "0"]}, "16 binary digits"), | |
| 115 | + "digit": ({**good, "words": w[:-1] + ["2" + w[-1][1:]]}, "16 binary digits"), | |
| 116 | + "number": ({**good, "words": w[:-1] + [1010]}, "16 binary digits"), | |
| 117 | + "repeat": ({**good, "words": w + [w[0]]}, "distinct"), | |
| 118 | + "empty": ({**good, "words": []}, "nonempty list"), | |
| 119 | + "string": ({**good, "words": "0101"}, "nonempty list"), | |
| 120 | + "size": ({**good, "n": 15}, '"n" must be one of'), | |
| 121 | + "bool": ({**good, "n": True}, '"n" must be one of'), | |
| 122 | + } | |
| 123 | + for name, (candidate, message) in cases.items(): | |
| 124 | + code, out, err, m = check({"ok.json": good, f"{name}.json": candidate}) | |
| 125 | + assert code == 1 and message in out and not err, (name, out, err) | |
| 126 | + assert m["subtasks"] == {"n16": 220}, (name, m) | |
| 127 | + | |
| 128 | + | |
| 129 | +def test_malformed_files_fail_cleanly(): | |
| 130 | + for content in ("{not json", "", b"\xff\xfe{"): | |
| 131 | + code, out, err, m = check({"bad.json": content}) | |
| 132 | + assert code == 1 and "unreadable" in out and not err and m is None, (out, err) | |
| 133 | + assert out.strip().splitlines()[-1] == "no valid candidates: 1 failed", out | |
| 134 | + | |
| 135 | + | |
| 136 | +def test_no_candidates(): | |
| 137 | + for files in ({}, {"notes.json": [1, 2]}, {"README.md": "# x"}): | |
| 138 | + code, out, err, m = check(files) | |
| 139 | + assert code == 0 and out.strip() == "no candidates to check" and m is None, out | |
| 140 | + with tempfile.TemporaryDirectory() as tmp: | |
| 141 | + code, out, err = run(JUDGE / "check.py", Path(tmp, "missing"), cwd=tmp) | |
| 142 | + assert code == 0 and out.strip() == "no candidates to check", out | |
| 143 | + | |
| 144 | + | |
| 145 | +def test_improves(): | |
| 146 | + with tempfile.TemporaryDirectory() as tmp: | |
| 147 | + main = Path(tmp, "main") | |
| 148 | + shutil.copytree(REPO / "constructions", main / "constructions") | |
| 149 | + route = Path(tmp, "route") | |
| 150 | + write(route, {"a.json": start("n17")}) | |
| 151 | + code, out, _ = run(JUDGE / "improves.py", route, main, cwd=main) | |
| 152 | + assert code == 1 and "n17: 316 words (route/a.json) against the default branch's 316, +0; the record is 349" in out, out | |
| 153 | + assert out.strip().endswith("no improvement on the default branch"), out | |
| 154 | + write(main / "constructions", {"n17.json": {"n": 17, "words": start("n17")["words"][:300]}}) | |
| 155 | + code, out, _ = run(JUDGE / "improves.py", route, main, cwd=main) | |
| 156 | + assert code == 0 and "+16: improves" in out and out.strip().endswith("improves on the default branch: n17; no new record"), out | |
| 157 | + code, out, _ = run(judge_with({"n17": 315}, tmp) / "improves.py", route, main, cwd=main) | |
| 158 | + assert code == 0 and "a new record, above 315" in out and out.strip().endswith("new records: n17"), out | |
| 159 | + code, out, _ = run(JUDGE / "improves.py", Path(tmp, "empty"), main, cwd=main) | |
| 160 | + assert code == 1 and out.startswith("no code"), out | |
| 161 | + code, out, _ = run(JUDGE / "improves.py", main / "routes", main, cwd=main, route_dir="routes") | |
| 162 | + assert code == 0 and out.strip() == "the default branch holds n16: 220, n17: 300, n18: 525; no new record", out | |
| 163 | + | |
| 164 | + | |
| 165 | +def test_check_format(): | |
| 166 | + tool = REPO / "tools" / "check_format.py" | |
| 167 | + code, out, err = run(tool, REPO / "constructions", cwd=REPO) | |
| 168 | + assert code == 0 and out.strip().endswith("3 candidates, 0 files with format errors"), out + err | |
| 169 | + bad = {"n": 17, "words": ["0" * 17, "0" * 16, "0" * 17]} | |
| 170 | + with tempfile.TemporaryDirectory() as tmp: | |
| 171 | + write(Path(tmp), {"bad.json": bad, "twice.json": {"n": 16, "words": ["0" * 16] * 2}, "broken.json": "{", "other.json": "[]"}) | |
| 172 | + code, out, err = run(tool, tmp, cwd=tmp) | |
| 173 | + assert code == 1 and "1 words are not strings of 17 binary digits" in out and "1 words are repeated" in out, out | |
| 174 | + assert "not valid JSON" in out and "ignored" in out and out.strip().endswith("2 candidates, 3 files with format errors"), out | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | +if __name__ == "__main__": | |
| 179 | + failed = 0 | |
| 180 | + for name, test in list(globals().items()): | |
| 181 | + if name.startswith("test_"): | |
| 182 | + try: | |
| 183 | + test() | |
| 184 | + print(f"ok {name}") | |
| 185 | + except Exception as exc: | |
| 186 | + failed += 1 | |
| 187 | + print(f"FAIL {name}: {exc!r}") | |
| 188 | + sys.exit(1 if failed else 0) | |
+8 −0 checks/verify.sbatch added View file
| @@ -0,0 +1,8 @@ | ||
| 1 | +#!/bin/bash | |
| 2 | +#SBATCH --job-name=verify | |
| 3 | +#SBATCH --time=5:00 | |
| 4 | +#SBATCH --cpus-per-task=1 | |
| 5 | +# The project's judge checks, exactly, every code in the submission format in the pushed route's folder (on the | |
| 6 | +# default branch, constructions/ too), and writes the score to metrics.json. The judge is checks/judge/, at the | |
| 7 | +# project's approved version. | |
| 8 | +python3 checks/judge/check.py "$SS_INPUT/$SS_ROUTE_DIR" | |
+1 −0 constructions/n16.json added View file
| @@ -0,0 +1 @@ | ||
| 1 | +{"n": 16, "words": ["0000000000000000", "0000000000000111", "0000000000111111", "0000000011100001", "0000000100011000", "0000001011011010", "0000001101010011", "0000001110011111", "0000010001001110", "0000011100111000", "0000100001110110", "0000101010110000", "0000101010111111", "0000110000010101", "0000110010111001", "0000111000000000", "0000111100010110", "0000111110010000", "0000111111101100", "0001000010101111", "0001000100001101", "0001000111100000", "0001000111111100", "0001010110000011", "0001010111110010", "0001011101100111", "0001100110001000", "0001100111101111", "0001101010101110", "0001110001010001", "0001110010001111", "0001110111000101", "0001111100111101", "0001111111100000", "0001111111111110", "0010000010001011", "0010000110000010", "0010001001010100", "0010001111111111", "0010011011101011", "0010011110011001", "0010100110011101", "0010100111100011", "0010101000100000", "0010110100100101", "0011000000010001", "0011000100111110", "0011000111001010", "0011010100011001", "0011011100001110", "0011011101110110", "0011100011011100", "0011100100000110", "0011100111010000", "0011101111111000", "0011110000100111", "0011110010011000", "0011110011011111", "0011110100000001", "0011111011001001", "0011111111000111", "0100000000100100", "0100000011110111", "0100000011111000", "0100001110000111", "0100010001100011", "0100010111011101", "0100100001011001", "0100100100000001", "0100101101000110", "0100110000001110", "0100110000110000", "0100110011101100", "0100111010100000", "0101001000001111", "0101001010111100", "0101001110000100", "0101010100110111", "0101101111000001", "0101110000010100", "0101110011110101", "0101111110011011", "0110000001010110", "0110000101101000", "0110000110001100", "0110001101000001", "0110001101011011", "0110001111110001", "0110010010100101", "0110011000111111", "0110011111111010", "0110101110011100", "0110110110010000", "0110110111110011", "0110111110001010", "0111000000000111", "0111000011111111", "0111000100010000", "0111001011110110", "0111001110010111", "0111010001011101", "0111010011000011", "0111011000010010", "0111101011100010", "0111110001111000", "0111110101110111", "0111111000011111", "0111111000100011", "0111111100000000", "0111111110101100", "1000000000111100", "1000001001110011", "1000001101001101", "1000001110000001", "1000001111110101", "1000010010010111", "1000010100001000", "1000011001101010", "1000011110101111", "1000100000010011", "1000100100100010", "1000110000111101", "1000110001001100", "1000111001111110", "1000111110010011", "1001001000111000", "1001010110100100", "1001011111111001", "1001100101100111", "1001100110000101", "1001101100111100", "1001110100111011", "1001111000100010", "1001111110000100", "1001111110101110", "1010000010100000", "1010000011001110", "1010001111100110", "1010010100011010", "1010100010111111", "1010100011001001", "1010101101110001", "1010101110001011", "1010101111011010", "1010110000000010", "1011001011110000", "1011010000001101", "1011011111011111", "1011100001110001", "1011100110100110", "1011110000110110", "1011110101000111", "1011110111011000", "1011111001011001", "1011111001100000", "1100000000110101", "1100000001111110", "1100000011100100", "1100001000000110", "1100001101100011", "1100001111011100", "1100010000000000", "1100010011011111", "1100010111000010", "1100011100110000", "1100101010000111", "1100101100101001", "1100110010010110", "1100110011110010", "1100111011111111", "1100111110001111", "1100111110101000", "1101000010011000", "1101000110001111", "1101001001110101", "1101001111110111", "1101010000100011", "1101010100000100", "1101010101100110", "1101100001111100", "1101100111011110", "1101110001010111", "1101110010110100", "1101110110000011", "1101111001100101", "1110000010101001", "1110000101011110", "1110001000011100", "1110001110100101", "1110010000110111", "1110011011011101", "1110011100000001", "1110011110001100", "1110100011000000", "1110100111110100", "1110110001110011", "1110111010011110", "1110111010100010", "1111000000000001", "1111000001111011", "1111000100010011", "1111000110011010", "1111001101100001", "1111010101001000", "1111010101111001", "1111011010101011", "1111011100001101", "1111011100111111", "1111011111100000", "1111100000001111", "1111100001010000", "1111100011111101", "1111100100001010", "1111110000011100", "1111110111111100", "1111111011101010", "1111111100100001", "1111111110011101", "1111111111100011", "1111111111111111"], "source": "EinsteinArena, problem two-deletion-code-16, submission #2622 by the agent nightshift-dc16 (2026-10-15T20:43Z): the record; from einsteinarena.com/api/solutions/best, 2026-10-22"} | |
+1 −0 constructions/n17.json added View file
| @@ -0,0 +1 @@ | ||
| 1 | +{"n": 17, "words": ["00000000000000000", "00000000000000111", "00000000000101010", "00000000000111111", "00000000001110000", "00000000010110011", "00000000101111010", "00000000110010001", "00000000111101111", "00000001010010111", "00000001101000000", "00000001110011100", "00000001111000011", "00000010011000110", "00000010101010100", "00000010110111011", "00000011000011101", "00000011011111000", "00000011111000100", "00000011111111101", "00000100111010101", "00000101000100000", "00000101100000011", "00000110001100111", "00000110101000101", "00000110101011110", "00000111000011000", "00000111011011001", "00000111110001111", "00001000100110101", "00001001100111111", "00001010000011110", "00001010010111000", "00001010110010010", "00001010111101110", "00001011110110000", "00001100000100001", "00001100011111001", "00001100111000001", "00001110001010110", "00001110010000100", "00001110111000110", "00001110111011111", "00001111001110100", "00001111110000000", "00001111111111000", "00010000110110010", "00010001110100111", "00010010000100101", "00010011111100101", "00010100101000011", "00010101000111011", "00010110001100100", "00010110010010111", "00010111010010001", "00010111011111010", "00010111101011011", "00011000000110100", "00011000010011111", "00011001100101000", "00011001101011101", "00011010000000000", "00011010111100100", "00011011011100111", "00011100000000111", "00011100011111110", "00011101010011010", "00011101100000101", "00011110000110011", "00011111100111001", "00011111110100001", "00011111111011110", "00100010010000010", "00100010100111001", "00100100011011110", "00100101010101011", "00100110110000111", "00100110111010100", "00101000001001100", "00101000101100000", "00101001001111100", "00101001011111111", "00101001101001010", "00101010111100011", "00101011010000000", "00101100001110001", "00101110011101011", "00101111010000110", "00101111100111110", "00110000100001001", "00110000110010110", "00110001110111000", "00110011000000011", "00110011100011111", "00110011110110110", "00110100000011101", "00110100101101001", "00110101100001100", "00110110111111001", "00110111001100001", "00110111100010101", "00111000001010010", "00111001110100000", "00111010000111111", "00111010010100111", "00111011001111000", "00111011111110111", "00111100000111100", "00111101010100100", "00111110000000001", "00111110110001111", "00111111000000111", "00111111100011000", "00111111111001010", "01000010001101100", "01000011110000010", "01000100000100111", "01000101101001100", "01000101110001011", "01000110011011011", "01000111111101011", "01001000001010000", "01001000110000100", "01001000111101000", "01001001010110001", "01001100011100110", "01001101101100000", "01001110010111100", "01001111000010000", "01001111010111111", "01010000010111111", "01010000011010011", "01010001000001101", "01010101000101010", "01010101010111101", "01010101110110010", "01010111111101100", "01011000100111010", "01011001000001000", "01011011101010111", "01011100001011011", "01011100110001110", "01011110011011001", "01011110111000101", "01100000001000011", "01100000010001000", "01100000010011110", "01100000111011010", "01100001001110000", "01100001111010111", "01100010110111110", "01100011000110001", "01100011010001110", "01100011111001001", "01100111000001010", "01100111111000111", "01101001001100110", "01101010001000001", "01101011001111111", "01101011110011101", "01101011111000000", "01101100111000100", "01101101001001011", "01101110100101000", "01101111111111101", "01110000110000000", "01110000110001111", "01110001010010100", "01110010100110111", "01110010101000011", "01110010111100010", "01110011101011001", "01110011111111000", "01110101000111001", "01110101101110100", "01110110000101110", "01110110110100110", "01111000000001100", "01111000110111101", "01111001000110000", "01111001111101111", "01111010110000001", "01111011100110110", "01111011110110000", "01111100101110110", "01111110001000010", "01111110110011100", "01111111011110011", "01111111100100011", "10000010100010110", "10000100101110011", "10000101100101001", "10000110101010000", "10001000011111101", "10001010110011110", "10001100010010010", "10001110011110001", "10001111100010100", "10010000000110001", "10010000001110110", "10010000111001001", "10010001101110111", "10010010001000110", "10010010111111100", "10010011000110101", "10010101001101000", "10010110010000001", "10010110101110110", "10010111101011000", "10011000100010111", "10011010011101111", "10011100110010011", "10011110010011101", "10100000100000001", "10100001000011111", "10100001011110010", "10100010000100100", "10100011001000011", "10100011101011101", "10100110100011000", "10100110110100101", "10100111000100111", "10101001111110000", "10101010101000111", "10101010111000001", "10101011111101111", "10101101110011100", "10101110001000100", "10101110111110011", "10101111100011011", "10101111110010010", "10110000010010101", "10110000110101000", "10110010000111100", "10110010101010110", "10110011011111010", "10110100101000000", "10110110000011001", "10110110001111011", "10111011110000111", "10111011110111110", "10111100000011111", "10111100010111000", "10111101100001000", "10111110010000011", "10111110011100111", "10111111011010101", "10111111011100000", "11000000001010101", "11000000011110100", "11000001101110001", "11000001110000111", "11000001111111011", "11000010000011100", "11000100101010111", "11000101011000000", "11000101110110011", "11000110010101100", "11000111110111100", "11001001000000000", "11001010000110011", "11001010011110101", "11001100010111110", "11001110101110000", "11001110110110111", "11010001010100010", "11010011110000110", "11010110011100011", "11011000000000111", "11011000001101111", "11011001011100111", "11011001110110001", "11011100001101001", "11011100100001101", "11011101001111100", "11011110101010011", "11100000001100000", "11100000001110111", "11100001001100011", "11100001110011100", "11100001111100000", "11100010000000110", "11100010101111111", "11100011100001001", "11100110010010000", "11100110101001111", "11100111111111011", "11101000001010100", "11101001000001111", "11101001011011010", "11101001111111001", "11101010010100101", "11101101011000010", "11101110000000000", "11101111001011111", "11101111101011010", "11101111110100001", "11110000001110010", "11110000101000001", "11110000111110110", "11110001001001110", "11110010111001000", "11110011010010101", "11110100110001100", "11110111100000100", "11110111111001011", "11111000010001011", "11111010110111111", "11111011101111000", "11111011110011001", "11111100000110110", "11111100101010100", "11111100111100010", "11111110100011101", "11111111111011100", "11111111111111111"], "source": "Lexicographic greedy, computed for this project: every binary word of length 17 in increasing order, kept when it shares no descendant with a word kept before. Not a record: no code of the record's size is public."} | |
+1 −0 constructions/n18.json added View file
| @@ -0,0 +1 @@ | ||
| 1 | +{"n": 18, "words": ["000000000000000000", "000000000000000111", "000000000000101010", "000000000000111111", "000000000001110000", "000000000010110011", "000000000101111010", "000000000110010001", "000000000111101111", "000000001010010111", "000000001101000000", "000000001110011100", "000000001111000011", "000000010011000110", "000000010101010100", "000000010110111011", "000000011000011101", "000000011011111000", "000000011111000100", "000000011111111101", "000000100111010101", "000000101000100000", "000000101100000011", "000000110001100111", "000000110101000101", "000000110101011110", "000000111000011000", "000000111011011001", "000000111110001111", "000001000100110101", "000001001100111111", "000001010000011110", "000001010010111000", "000001010110010010", "000001010111101110", "000001011110110000", "000001100000100001", "000001100011111001", "000001100111000001", "000001110001010110", "000001110010000100", "000001110111000110", "000001110111011111", "000001111001110100", "000001111110000000", "000001111111111000", "000010000110110010", "000010001110100111", "000010010000100101", "000010011111100101", "000010100101000011", "000010101000111011", "000010110001100100", "000010110010010111", "000010111010010001", "000010111011111010", "000010111101011011", "000011000000110100", "000011000010011111", "000011001100101000", "000011001101011101", "000011010000000000", "000011010111100100", "000011011011100111", "000011100000000111", "000011100011111110", "000011101010011010", "000011101100000101", "000011110000110011", "000011111100111001", "000011111110100001", "000011111111011110", "000100010010000010", "000100010100111001", "000100100011011110", "000100101010101011", "000100110110000111", "000100110111010100", "000101000001001100", "000101000101100000", "000101001001111100", "000101001011111111", "000101001101001010", "000101010111100011", "000101011010000000", "000101100001110001", "000101110011101011", "000101111010000110", "000101111100111110", "000110000100001001", "000110000110010110", "000110001110111000", "000110011000000011", "000110011100011111", "000110011110110110", "000110100000011101", "000110100101101001", "000110101100001100", "000110110111111001", "000110111001100001", "000110111100010101", "000111000001010010", "000111001110100000", "000111010000111111", "000111010010100111", "000111011001111000", "000111011111110111", "000111100000111100", "000111101010100100", "000111110000000001", "000111110110001111", "000111111000000111", "000111111100011000", "000111111111001010", "001000010001101100", "001000011110000010", "001000100000100111", "001000101101001100", "001000101110001011", "001000110011011011", "001000111111101011", "001001000001010000", "001001000110000100", "001001000111101000", "001001001010110001", "001001100011100110", "001001101101100000", "001001110010111100", "001001111000010000", "001001111010111111", "001010000010111111", "001010000011010011", "001010001000001101", "001010101000101010", "001010101010111101", "001010101110110010", "001010111111101100", "001011000100111010", "001011001000001000", "001011011101010111", "001011100001011011", "001011100110001110", "001011110011011001", "001011110111000101", "001100000001000011", "001100000010001000", "001100000010011110", "001100000111011010", "001100001001110000", "001100001111010111", "001100010110111110", "001100011000110001", "001100011010001110", "001100011111001001", "001100111000001010", "001100111111000111", "001101001001100110", "001101010001000001", "001101011001111111", "001101011110011101", "001101011111000000", "001101100111000100", "001101101001001011", "001101110100101000", "001101111111111101", "001110000110000000", "001110000110001111", "001110001010010100", "001110010100110111", "001110010101000011", "001110010111100010", "001110011101011001", "001110011111111000", "001110101000111001", "001110101101110100", "001110110000101110", "001110110110100110", "001111000000001100", "001111000110111101", "001111001000110000", "001111001111101111", "001111010110000001", "001111011100110110", "001111011110110000", "001111100101110110", "001111110001000010", "001111110110011100", "001111111011110011", "001111111100100011", "010000010100010110", "010000100101110011", "010000101100101001", "010000110101010000", "010001000011111101", "010001010110011110", "010001100010010010", "010001110011110001", "010001111100010100", "010010000000110001", "010010000001110110", "010010000111001001", "010010001101110111", "010010010001000110", "010010010111111100", "010010011000110101", "010010101001101000", "010010110010000001", "010010110101110110", "010010111101011000", "010011000100010111", "010011010011101111", "010011100110010011", "010011110010011101", "010100000100000001", "010100001000011111", "010100001011110010", "010100010000100100", "010100011001000011", "010100011101011101", "010100110100011000", "010100110110100101", "010100111000100111", "010101001111110000", "010101010101000111", "010101010111000001", "010101011111101111", "010101101110011100", "010101110001000100", "010101110111110011", "010101111100011011", "010101111110010010", "010110000010010101", "010110000110101000", "010110010000111100", "010110010101010110", "010110011011111010", "010110100101000000", "010110110000011001", "010110110001111011", "010111011110000111", "010111011110111110", "010111100000011111", "010111100010111000", "010111101100001000", "010111110010000011", "010111110011100111", "010111111011010101", "010111111011100000", "011000000001010101", "011000000011110100", "011000001101110001", "011000001110000111", "011000001111111011", "011000010000011100", "011000100101010111", "011000101011000000", "011000101110110011", "011000110010101100", "011000111110111100", "011001001000000000", "011001010000110011", "011001010011110101", "011001100010111110", "011001110101110000", "011001110110110111", "011010001010100010", "011010011110000110", "011010110011100011", "011011000000000111", "011011000001101111", "011011001011100111", "011011001110110001", "011011100001101001", "011011100100001101", "011011101001111100", "011011110101010011", "011100000001100000", "011100000001110111", "011100001001100011", "011100001110011100", "011100001111100000", "011100010000000110", "011100010101111111", "011100011100001001", "011100110010010000", "011100110101001111", "011100111111111011", "011101000001010100", "011101001000001111", "011101001011011010", "011101001111111001", "011101010010100101", "011101101011000010", "011101110000000000", "011101111001011111", "011101111101011010", "011101111110100001", "011110000001110010", "011110000101000001", "011110000111110110", "011110001001001110", "011110010111001000", "011110011010010101", "011110100110001100", "011110111100000100", "011110111111001011", "011111000010001011", "011111010110111111", "011111011101111000", "011111011110011001", "011111100000110110", "011111100101010100", "011111100111100010", "011111110100011101", "011111111111011100", "011111111111111111", "100000011110010110", "100000100010100010", "100000110100011001", "100001001001001110", "100001010011111011", "100001100000101011", "100001101101101010", "100001101110010011", "100001110000111101", "100010000000101110", "100010000110001000", "100010001011110000", "100010011110000001", "100010011110111001", "100010100010101101", "100010110101101111", "100010111011100000", "100011000110100001", "100011011000100010", "100011100100000110", "100011101100101101", "100011111101101000", "100100000101100111", "100100001101110100", "100100010100100101", "100100100110000011", "100100110000101100", "100100111110101110", "100101000110011111", "100101001100100000", "100101011111010001", "100101110010100101", "100101111000011010", "100110010011010101", "100110011011001100", "100110100011111001", "100110101000000111", "100110111011110010", "100111000000000101", "100111001001011110", "100111011010000100", "100111100011100011", "100111110111011101", "100111111000011111", "101000000100000111", "101000000100111000", "101000000110110101", "101000010111101111", "101000011001100110", "101000011110100011", "101000100101100001", "101000110011111100", "101000111100110111", "101000111111111101", "101001001110100100", "101001101011011001", "101010000011100000", "101010000110001101", "101010100011101110", "101010101000000010", "101010101001001100", "101011011101000110", "101011100010111111", "101011101001100001", "101011110011101010", "101100001010111101", "101100001111111000", "101100010111001010", "101100011100000000", "101100100010100011", "101100111000110110", "101100111101000010", "101101010110110000", "101101010110111011", "101101100110001111", "101101101111111100", "101101110011001000", "101110000011010110", "101110010011110011", "101110011000001011", "101110011110110100", "101110110001110000", "101110111100010001", "101111010000001001", "101111010001010111", "101111010100110100", "101111011001111101", "101111101100010110", "101111111001000000", "101111111100110111", "101111111110100110", "110000000000100100", "110000000011111110", "110000000100011111", "110000000110100110", "110000010101101100", "110000011000000110", "110000011100101000", "110000011100111110", "110000011111100100", "110000110000110000", "110000110110001111", "110001000000000011", "110001000100011010", "110001010011100111", "110001010100001011", "110001100011101010", "110001100110111111", "110001101111100010", "110001110011000100", "110001111010100001", "110010001011110011", "110010010110010110", "110010011001111000", "110010111010011110", "110010111110110101", "110011000000011011", "110011000001110001", "110011000100000100", "110011000111100000", "110011010101001000", "110011010111110110", "110011011100000001", "110011110000001000", "110011111000100110", "110011111111100001", "110100001001000000", "110100010001011110", "110100011010101011", "110100110000001001", "110100110000110111", "110100111001111011", "110100111111001101", "110101000101101000", "110101001100010001", "110101011110010100", "110101100101011101", "110101101000001110", "110101101100110011", "110101110111011000", "110101111011111111", "110110000000100010", "110110001010011001", "110110010110111100", "110110010111111111", "110110110111101001", "110111010110010111", "110111100100100010", "110111101110000011", "110111101111001110", "110111110000111100", "110111111010111001", "111000000001111001", "111000001110100101", "111000010001001001", "111000011101110111", "111000100001011000", "111000111001000111", "111000111010011000", "111001000011111111", "111001001001011011", "111001010001100010", "111001011111000011", "111001100111001001", "111001101001011100", "111001111111000000", "111010000011111000", "111010000100001010", "111010011010111110", "111010100111111010", "111010101110001101", "111010110101000001", "111011000110000011", "111011011111001111", "111011100000010111", "111011100010110010", "111011110110001100", "111100001101100010", "111100010100011111", "111100011110011101", "111100100000001000", "111100100110000111", "111100110010100110", "111101000001001101", "111101000101110101", "111101001001010000", "111101100001111110", "111101100110110111", "111101101111110000", "111101110011000101", "111101110111011110", "111110000000000011", "111110000011110111", "111110000100111100", "111110000111000000", "111110001111100100", "111110011011010001", "111110011101011011", "111110100001100011", "111110111111101101", "111111001000111000", "111111001100000001", "111111010011101011", "111111011100100100", "111111100000000110", "111111100011001111", "111111101010000111", "111111101010110000", "111111111111100011"], "source": "Lexicographic greedy, computed for this project: every binary word of length 18 in increasing order, kept when it shares no descendant with a word kept before. Not a record: no code of the record's size is public."} | |
+0 −0 poster.webp added View file
+6 −0 posters.json added View file
| @@ -0,0 +1,6 @@ | ||
| 1 | +{ | |
| 2 | + "poster.webp": { | |
| 3 | + "style": "poster", | |
| 4 | + "idea": "A tactile slate board with binary tile strings, brass tweezers removing two tiles, and a shared shorter trace showing deletion correction." | |
| 5 | + } | |
| 6 | +} | |
+50 −0 tools/check_format.py added View file
| @@ -0,0 +1,50 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""Checks that the candidates in a folder follow the submission format in README.md: JSON shape, n, and words that are | |
| 3 | +distinct strings of n binary digits. It does not check that no two words share a descendant. | |
| 4 | + | |
| 5 | +usage: python3 tools/check_format.py routes/<branch> (or one .json file) | |
| 6 | +""" | |
| 7 | +import json | |
| 8 | +import pathlib | |
| 9 | +import sys | |
| 10 | + | |
| 11 | + | |
| 12 | +def errors(candidate): | |
| 13 | + n, words = candidate.get("n"), candidate.get("words") | |
| 14 | + if type(n) is not int or n not in (16, 17, 18): | |
| 15 | + return ['"n" must be one of the integers 16, 17, 18'] | |
| 16 | + if not isinstance(words, list) or not words: | |
| 17 | + return ['"words" must be a nonempty list'] | |
| 18 | + bad = [w for w in words if not isinstance(w, str) or len(w) != n or not set(w) <= {"0", "1"}] | |
| 19 | + if bad: | |
| 20 | + return [f"{len(bad)} words are not strings of {n} binary digits, such as {str(bad[0])[:40]!r}"] | |
| 21 | + return [] if len(set(words)) == len(words) else [f"{len(words) - len(set(words))} words are repeated"] | |
| 22 | + | |
| 23 | + | |
| 24 | +if len(sys.argv) != 2: | |
| 25 | + sys.exit(__doc__) | |
| 26 | +target = pathlib.Path(sys.argv[1]) | |
| 27 | +if target.is_file() and target.suffix != ".json": | |
| 28 | + sys.exit(f"{target}: candidates are .json files") | |
| 29 | +files = [target] if target.is_file() else sorted(target.rglob("*.json")) | |
| 30 | +found = bad = 0 | |
| 31 | +for path in files: | |
| 32 | + if path.stat().st_size > 1_000_000: | |
| 33 | + print(f"{path}: over 1 MB") | |
| 34 | + bad += 1 | |
| 35 | + continue | |
| 36 | + try: | |
| 37 | + candidate = json.loads(path.read_text()) | |
| 38 | + except Exception as exc: | |
| 39 | + print(f"{path}: not valid JSON ({exc})") | |
| 40 | + bad += 1 | |
| 41 | + continue | |
| 42 | + if not isinstance(candidate, dict) or "words" not in candidate: | |
| 43 | + print(f'{path}: not a candidate (no "words" key); ignored') | |
| 44 | + continue | |
| 45 | + found += 1 | |
| 46 | + problems = errors(candidate) | |
| 47 | + print(f"{path}: {'; '.join(problems)}" if problems else f"{path}: ok (n{candidate['n']}, {len(candidate['words'])} words)") | |
| 48 | + bad += bool(problems) | |
| 49 | +print(f"{found} candidates, {bad} files with format errors") | |
| 50 | +sys.exit(1 if bad else 0) | |
