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.
| 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")) |
