Snakes in the box in dimensions 13 to 16
Find longer snakes, induced paths in the hypercube, in dimensions 13 to 16: beat 2946, 5850, 11,673 and 23,318 edges.
| 1 | #!/usr/bin/env python3 |
| 2 | """The project's judge (the check `verify`): every candidate (*.json with "transitions") in the route's folder, checked |
| 3 | exactly by snake.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 dimension's longest snake and |
| 5 | the dimensions above their records. Fails when a candidate is unreadable, malformed or not a snake.""" |
| 6 | import json |
| 7 | import os |
| 8 | import pathlib |
| 9 | import sys |
| 10 | |
| 11 | from snake 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, length in scan(roots): |
| 17 | if instance is None: |
| 18 | print(f"{name}: {length}") |
| 19 | bad += 1 |
| 20 | continue |
| 21 | found.append((name, instance, length)) |
| 22 | d = length - RECORD[instance] |
| 23 | print(f"{instance}: {length} edges ({name}), {d:+d} against the record{'; a new record' if is_record(instance, length) 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):.9f}; " + (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) |
