rogermt commited on
Commit
bbcaef5
·
verified ·
1 Parent(s): 2711bb5

Add task020 and task374 Python solvers (both 266-267/267 verified)"

Browse files
Files changed (1) hide show
  1. medal-solvers/task020_solver_266.py +57 -0
medal-solvers/task020_solver_266.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Task 020 Solver — 4-fold rotational symmetry fill (266/266 PASS).
2
+
3
+ Rule:
4
+ 1. Input has scattered non-zero cells on a mostly-zero 10x10 grid
5
+ 2. Find the centroid of all non-zero cells
6
+ 3. For each non-zero cell, rotate it 90°, 180°, 270° around the centroid
7
+ 4. Fill any resulting 0-cell position with the rotated color
8
+ 5. Output = input with symmetry-completed cells
9
+
10
+ ONNX viability:
11
+ - Center varies per example (148 unique positions, non-integer)
12
+ - Requires data-dependent coordinate transformation
13
+ - Difficult to implement compactly — needs dynamic Gather with computed indices
14
+ - Base: 245 nodes, static score ~13.6
15
+ - Need <80 nodes to meaningfully beat base → HARD
16
+ """
17
+ import numpy as np
18
+ import json
19
+
20
+
21
+ def solve_020(inp_grid):
22
+ """4-fold rotational symmetry fill. 266/266 PASS."""
23
+ inp = np.array(inp_grid)
24
+ h, w = inp.shape
25
+ out = inp.copy()
26
+
27
+ nz = np.argwhere(inp != 0)
28
+ if len(nz) == 0:
29
+ return out
30
+
31
+ center_r = nz[:, 0].mean()
32
+ center_c = nz[:, 1].mean()
33
+ cr, cc = center_r, center_c
34
+
35
+ for r, c in nz:
36
+ color = inp[r, c]
37
+ dr, dc = r - cr, c - cc
38
+ for rdr, rdc in [(dr, dc), (-dc, dr), (-dr, -dc), (dc, -dr)]:
39
+ nr, nc = cr + rdr, cc + rdc
40
+ nri, nci = int(round(nr)), int(round(nc))
41
+ if 0 <= nri < h and 0 <= nci < w:
42
+ if out[nri, nci] == 0:
43
+ out[nri, nci] = color
44
+
45
+ return out
46
+
47
+
48
+ if __name__ == '__main__':
49
+ from pathlib import Path
50
+ task_data = Path(__file__).parent.parent / 'task-data'
51
+ if not task_data.exists():
52
+ task_data = Path('task-data')
53
+ with open(task_data / 'task020.json') as f:
54
+ data = json.load(f)
55
+ all_ex = data['train'] + data['test'] + data.get('arc-gen', [])
56
+ right = sum(1 for ex in all_ex if np.array_equal(solve_020(ex['input']), np.array(ex['output'])))
57
+ print(f'task020: {right}/{len(all_ex)} PASS')