Download graders/ea_circles_rectangle_21/check.py from amphora/MathConstructOptimize-Envs: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/datasets/amphora/MathConstructOptimize-Envs/resolve/main/graders/ea_circles_rectangle_21/check.py
- Command line
-
hf download hf://datasets/amphora/MathConstructOptimize-Envs/graders/ea_circles_rectangle_21/check.py
-
curl -L -o check.py https://huggingface.co/datasets/amphora/MathConstructOptimize-Envs/resolve/main/graders/ea_circles_rectangle_21/check.py
1.08 kB
| """21 disjoint circles in a rectangle of perimeter 4, maximize the sum of radii | |
| (EinsteinArena circles-rectangle, MIT). | |
| Upstream bug fixed: the perimeter test is exact (Fractions) upstream but the disjointness test compares | |
| float sqrt distances; both are exact here.""" | |
| from fractions import Fraction | |
| from run import Invalid, float_matrix | |
| def check(inst, ans): | |
| n = inst["n"] | |
| c = float_matrix(ans.get("circles"), n, 3, "circles") | |
| F = [tuple(Fraction(v) for v in row) for row in c] | |
| if any(r <= 0 for _, _, r in F): | |
| raise Invalid("radii must be positive") | |
| w = max(x + r for x, _, r in F) - min(x - r for x, _, r in F) | |
| h = max(y + r for _, y, r in F) - min(y - r for _, y, r in F) | |
| if w + h > 2: | |
| raise Invalid("bounding rectangle violates width + height <= 2") | |
| for i in range(n): | |
| xi, yi, ri = F[i] | |
| for j in range(i + 1, n): | |
| xj, yj, rj = F[j] | |
| if (xi - xj) ** 2 + (yi - yj) ** 2 < (ri + rj) ** 2: | |
| raise Invalid(f"circles {i} and {j} overlap") | |
| return sum(r for _, _, r in c), {} | |