The Erdős minimum overlap problem
Pin down the constant c ≈ 0.38 such that every split of {1,…,2N} into equal halves has a difference occurring cN times.

| 1 | #!/usr/bin/env python3 |
| 2 | """Checks the shape of construction files, as the Submission format in README.md states it: JSON objects with a |
| 3 | nonempty list "values" of at most 16384 heights (numbers, "p/q" strings, or integers over a positive integer |
| 4 | "denominator"). It does not check admissibility and computes no score. |
| 5 | python3 tools/check_format.py <file or folder> ...""" |
| 6 | import json |
| 7 | import pathlib |
| 8 | import re |
| 9 | import sys |
| 10 | |
| 11 | RATIONAL = re.compile(r"^\s*[+-]?\d+(\.\d+)?([eE][+-]?\d+)?(\s*/\s*\d+)?\s*$") |
| 12 | |
| 13 | |
| 14 | def problems(path): |
| 15 | try: |
| 16 | data = json.loads(path.read_text()) |
| 17 | except Exception as exc: |
| 18 | return [f"not JSON ({exc})"] |
| 19 | if not isinstance(data, dict) or "values" not in data: |
| 20 | return None # not a construction: the check skips it |
| 21 | values, out = data["values"], [] |
| 22 | if not isinstance(values, list) or not values: |
| 23 | return ['"values" must be a nonempty list'] |
| 24 | if len(values) > 16384: |
| 25 | out.append(f'"values" has {len(values)} heights; at most 16384') |
| 26 | den = data.get("denominator") |
| 27 | if den is not None and (isinstance(den, bool) or not isinstance(den, int) or den <= 0): |
| 28 | out.append('"denominator" must be a positive integer') |
| 29 | for i, v in enumerate(values): |
| 30 | ok = (isinstance(v, (int, float)) and not isinstance(v, bool) and v == v and v not in (float("inf"), float("-inf"))) \ |
| 31 | or (isinstance(v, str) and RATIONAL.match(v)) |
| 32 | if not ok: |
| 33 | out.append(f"height {i} is not a finite number or a 'p/q' string: {v!r}") |
| 34 | break |
| 35 | return out |
| 36 | |
| 37 | |
| 38 | bad = 0 |
| 39 | for arg in sys.argv[1:] or ["."]: |
| 40 | root = pathlib.Path(arg) |
| 41 | for path in sorted(root.rglob("*.json")) if root.is_dir() else [root]: |
| 42 | found = problems(path) |
| 43 | if found is None: |
| 44 | continue |
| 45 | print(f"{path}: {'ok' if not found else '; '.join(found)}") |
| 46 | bad += bool(found) |
| 47 | sys.exit(1 if bad else 0) |