grapheneaffiliates commited on
Commit
504c7da
·
verified ·
1 Parent(s): d8ab212

Upload data\arc2_solutions_retry9.json with huggingface_hub

Browse files
Files changed (1) hide show
  1. data//arc2_solutions_retry9.json +1 -1
data//arc2_solutions_retry9.json CHANGED
@@ -1 +1 @@
1
- {"80a900e0": "def solve(grid):\n \"\"\"Diamond shapes on checkerboard - extend rays from edge endpoints.\"\"\"\n rows, cols = len(grid), len(grid[0])\n out = copy.deepcopy(grid)\n\n special = {}\n for r in range(rows):\n for c in range(cols):\n if grid[r][c] not in (0, 1):\n special[(r,c)] = grid[r][c]\n\n visited = set()\n diamonds = []\n for (r,c) in special:\n if (r,c) in visited:\n continue\n stack = [(r,c)]\n comp = set()\n while stack:\n cr2, cc2 = stack.pop()\n if (cr2,cc2) in comp:\n continue\n comp.add((cr2,cc2))\n for dr, dc in [(-1,-1),(-1,1),(1,-1),(1,1)]:\n nr, nc = cr2+dr, cc2+dc\n if (nr,nc) in special and (nr,nc) not in comp:\n stack.append((nr,nc))\n visited |= comp\n diamonds.append(comp)\n\n for diamond in diamonds:\n center_r = sum(r for r,c in diamond) / len(diamond)\n center_c = sum(c for r,c in diamond) / len(diamond)\n\n colors = Counter(special[(r,c)] for r,c in diamond)\n interior_color = colors.most_common(1)[0][0]\n\n border_cells = {(r,c): special[(r,c)] for (r,c) in diamond if special[(r,c)] != interior_color}\n\n used = set()\n segments = []\n\n for (r,c) in sorted(border_cells.keys()):\n if (r,c) in used:\n continue\n color = border_cells[(r,c)]\n for dr, dc in [(1,1), (1,-1)]:\n seg = [(r,c)]\n rr, cc2 = r+dr, c+dc\n while (rr,cc2) in border_cells and border_cells[(rr,cc2)] == color:\n seg.append((rr,cc2))\n rr += dr; cc2 += dc\n rr, cc2 = r-dr, c-dc\n while (rr,cc2) in border_cells and border_cells[(rr,cc2)] == color:\n seg.insert(0, (rr,cc2))\n rr -= dr; cc2 -= dc\n\n if len(seg) >= 2:\n seg_set = frozenset(seg)\n if not any(frozenset(s[0]) == seg_set for s in segments):\n segments.append((seg, color, (dr, dc)))\n for p in seg:\n used.add(p)\n break\n else:\n used.add((r,c))\n\n for seg, color, (dr, dc) in segments:\n if (dr, dc) == (1, 1):\n perps = [(-1, 1), (1, -1)]\n else:\n perps = [(1, 1), (-1, -1)]\n\n mid_r = (seg[0][0] + seg[-1][0]) / 2\n mid_c = (seg[0][1] + seg[-1][1]) / 2\n\n outward = None\n for perp in perps:\n test_r = mid_r + perp[0]\n test_c = mid_c + perp[1]\n dist_orig = (mid_r - center_r)**2 + (mid_c - center_c)**2\n dist_new = (test_r - center_r)**2 + (test_c - center_c)**2\n if dist_new > dist_orig:\n outward = perp\n break\n\n if outward is None:\n outward = perps[0]\n\n for endpoint in [seg[0], seg[-1]]:\n rr, cc2 = endpoint\n while True:\n rr += outward[0]\n cc2 += outward[1]\n if rr < 0 or rr >= rows or cc2 < 0 or cc2 >= cols:\n break\n if (rr, cc2) in special:\n break\n if out[rr][cc2] == 1:\n out[rr][cc2] = color\n\n return out\n", "8e5c0c38": "def solve(grid):\n \"\"\"Make each pattern LR symmetric by removing asymmetric cells.\"\"\"\n rows, cols = len(grid), len(grid[0])\n out = copy.deepcopy(grid)\n\n # Find background color (most common)\n flat = [grid[r][c] for r in range(rows) for c in range(cols)]\n bg = Counter(flat).most_common(1)[0][0]\n\n # Group ALL cells of same non-background color as one pattern\n color_groups = {}\n for r in range(rows):\n for c in range(cols):\n if grid[r][c] != bg:\n color = grid[r][c]\n if color not in color_groups:\n color_groups[color] = set()\n color_groups[color].add((r,c))\n patterns = [(cells, color) for color, cells in color_groups.items()]\n\n for comp, color in patterns:\n if len(comp) < 3:\n continue\n\n # Find columns used\n all_cols = sorted(set(c for r,c in comp))\n\n # Try all possible center columns (integer and half-integer)\n best_center = None\n best_removals = len(comp) + 1\n\n # Possible centers\n min_c = min(all_cols)\n max_c = max(all_cols)\n\n for center2 in range(min_c * 2, max_c * 2 + 1): # center * 2 to handle half-integers\n center = center2 / 2.0\n removals = 0\n for (r, c) in comp:\n mirror_c = int(2 * center - c)\n if (r, mirror_c) not in comp:\n removals += 1\n if removals < best_removals:\n best_removals = removals\n best_center = center\n\n if best_center is not None:\n # Remove cells without LR mirrors\n for (r, c) in comp:\n mirror_c = int(2 * best_center - c)\n if (r, mirror_c) not in comp:\n out[r][c] = bg\n\n return out\n"}
 
1
+ {"80a900e0": "import copy\nfrom collections import Counter, deque\n\ndef solve(grid):\n \"\"\"Diamond shapes on checkerboard - extend rays from edge endpoints.\"\"\"\n rows, cols = len(grid), len(grid[0])\n out = copy.deepcopy(grid)\n\n special = {}\n for r in range(rows):\n for c in range(cols):\n if grid[r][c] not in (0, 1):\n special[(r,c)] = grid[r][c]\n\n visited = set()\n diamonds = []\n for (r,c) in special:\n if (r,c) in visited:\n continue\n stack = [(r,c)]\n comp = set()\n while stack:\n cr2, cc2 = stack.pop()\n if (cr2,cc2) in comp:\n continue\n comp.add((cr2,cc2))\n for dr, dc in [(-1,-1),(-1,1),(1,-1),(1,1)]:\n nr, nc = cr2+dr, cc2+dc\n if (nr,nc) in special and (nr,nc) not in comp:\n stack.append((nr,nc))\n visited |= comp\n diamonds.append(comp)\n\n for diamond in diamonds:\n center_r = sum(r for r,c in diamond) / len(diamond)\n center_c = sum(c for r,c in diamond) / len(diamond)\n\n colors = Counter(special[(r,c)] for r,c in diamond)\n interior_color = colors.most_common(1)[0][0]\n\n border_cells = {(r,c): special[(r,c)] for (r,c) in diamond if special[(r,c)] != interior_color}\n\n used = set()\n segments = []\n\n for (r,c) in sorted(border_cells.keys()):\n if (r,c) in used:\n continue\n color = border_cells[(r,c)]\n for dr, dc in [(1,1), (1,-1)]:\n seg = [(r,c)]\n rr, cc2 = r+dr, c+dc\n while (rr,cc2) in border_cells and border_cells[(rr,cc2)] == color:\n seg.append((rr,cc2))\n rr += dr; cc2 += dc\n rr, cc2 = r-dr, c-dc\n while (rr,cc2) in border_cells and border_cells[(rr,cc2)] == color:\n seg.insert(0, (rr,cc2))\n rr -= dr; cc2 -= dc\n\n if len(seg) >= 2:\n seg_set = frozenset(seg)\n if not any(frozenset(s[0]) == seg_set for s in segments):\n segments.append((seg, color, (dr, dc)))\n for p in seg:\n used.add(p)\n break\n else:\n used.add((r,c))\n\n for seg, color, (dr, dc) in segments:\n if (dr, dc) == (1, 1):\n perps = [(-1, 1), (1, -1)]\n else:\n perps = [(1, 1), (-1, -1)]\n\n mid_r = (seg[0][0] + seg[-1][0]) / 2\n mid_c = (seg[0][1] + seg[-1][1]) / 2\n\n outward = None\n for perp in perps:\n test_r = mid_r + perp[0]\n test_c = mid_c + perp[1]\n dist_orig = (mid_r - center_r)**2 + (mid_c - center_c)**2\n dist_new = (test_r - center_r)**2 + (test_c - center_c)**2\n if dist_new > dist_orig:\n outward = perp\n break\n\n if outward is None:\n outward = perps[0]\n\n for endpoint in [seg[0], seg[-1]]:\n rr, cc2 = endpoint\n while True:\n rr += outward[0]\n cc2 += outward[1]\n if rr < 0 or rr >= rows or cc2 < 0 or cc2 >= cols:\n break\n if (rr, cc2) in special:\n break\n if out[rr][cc2] == 1:\n out[rr][cc2] = color\n\n return out\n", "88e364bc": "import copy\nfrom collections import Counter, deque\n\ndef solve(grid):\n \"\"\"Move 4s in direction indicated by template, until adjacent to wall.\"\"\"\n rows, cols = len(grid), len(grid[0])\n out = copy.deepcopy(grid)\n\n flat = [grid[r][c] for r in range(rows) for c in range(cols)]\n bg = Counter(flat).most_common(1)[0][0]\n\n # Find all potential wall colors (any non-bg, non-4, non-0 color)\n all_colors = set()\n for r in range(rows):\n for c in range(cols):\n v = grid[r][c]\n if v not in (bg, 4, 0):\n all_colors.add(v)\n\n wall_colors = set()\n templates = {}\n\n for wc in all_colors:\n wc_cells = set()\n for r in range(rows):\n for c in range(cols):\n if grid[r][c] == wc:\n wc_cells.add((r, c))\n\n visited = set()\n for start in sorted(wc_cells):\n if start in visited:\n continue\n comp = set()\n q = deque([start])\n while q:\n rr, cc = q.popleft()\n if (rr, cc) in comp:\n continue\n comp.add((rr, cc))\n for dr, dc in [(0,1),(0,-1),(1,0),(-1,0)]:\n nr, nc = rr+dr, cc+dc\n if (nr, nc) in wc_cells and (nr, nc) not in comp:\n q.append((nr, nc))\n visited |= comp\n\n min_r = min(r for r, c in comp)\n max_r = max(r for r, c in comp)\n min_c = min(c for r, c in comp)\n max_c = max(c for r, c in comp)\n\n has_interior = False\n interior_cells_2 = []\n for r in range(min_r, max_r + 1):\n for c in range(min_c, max_c + 1):\n if grid[r][c] in (1, 2):\n has_interior = True\n if grid[r][c] == 2:\n interior_cells_2.append((r - min_r, c - min_c))\n\n if has_interior and interior_cells_2:\n int_min_r = min_r + 1\n int_max_r = max_r - 1\n int_min_c = min_c + 1\n int_max_c = max_c - 1\n\n center_r = (int_min_r + int_max_r) / 2.0 - min_r\n center_c = (int_min_c + int_max_c) / 2.0 - min_c\n\n avg_r = sum(r for r, c in interior_cells_2) / len(interior_cells_2)\n avg_c = sum(c for r, c in interior_cells_2) / len(interior_cells_2)\n\n dr = avg_r - center_r\n dc = avg_c - center_c\n\n dir_r = 0 if abs(dr) < 0.3 else (1 if dr > 0 else -1)\n dir_c = 0 if abs(dc) < 0.3 else (1 if dc > 0 else -1)\n\n templates[wc] = (dir_r, dir_c)\n wall_colors.add(wc)\n\n fours = []\n for r in range(rows):\n for c in range(cols):\n if grid[r][c] == 4:\n fours.append((r, c))\n\n for r, c in fours:\n # Determine wall color by scanning cardinal directions\n # Use the nearest wall in each cardinal direction\n wall_votes = Counter()\n for ddr, ddc in [(0,1),(0,-1),(1,0),(-1,0)]:\n rr, cc = r + ddr, c + ddc\n while 0 <= rr < rows and 0 <= cc < cols:\n if grid[rr][cc] in wall_colors:\n wall_votes[grid[rr][cc]] += 1\n break\n elif grid[rr][cc] not in (bg, 4, 0):\n break\n rr += ddr\n cc += ddc\n wall_color = wall_votes.most_common(1)[0][0] if wall_votes else None\n\n if wall_color is None or wall_color not in templates:\n continue\n\n dir_r, dir_c = templates[wall_color]\n\n if dir_r == 0 and dir_c == 0:\n continue\n\n out[r][c] = bg\n\n nr, nc = r, c\n while True:\n nnr, nnc = nr + dir_r, nc + dir_c\n if nnr < 0 or nnr >= rows or nnc < 0 or nnc >= cols:\n break\n if grid[nnr][nnc] == wall_color:\n break\n nr, nc = nnr, nnc\n\n out[nr][nc] = 4\n\n return out\n", "8e5c0c38": "import copy\nfrom collections import Counter, deque\n\ndef solve(grid):\n \"\"\"Make each pattern LR symmetric by removing asymmetric cells.\"\"\"\n rows, cols = len(grid), len(grid[0])\n out = copy.deepcopy(grid)\n\n # Find background color (most common)\n flat = [grid[r][c] for r in range(rows) for c in range(cols)]\n bg = Counter(flat).most_common(1)[0][0]\n\n # Group ALL cells of same non-background color as one pattern\n color_groups = {}\n for r in range(rows):\n for c in range(cols):\n if grid[r][c] != bg:\n color = grid[r][c]\n if color not in color_groups:\n color_groups[color] = set()\n color_groups[color].add((r,c))\n patterns = [(cells, color) for color, cells in color_groups.items()]\n\n for comp, color in patterns:\n if len(comp) < 3:\n continue\n\n # Find columns used\n all_cols = sorted(set(c for r,c in comp))\n\n # Try all possible center columns (integer and half-integer)\n best_center = None\n best_removals = len(comp) + 1\n\n # Possible centers\n min_c = min(all_cols)\n max_c = max(all_cols)\n\n for center2 in range(min_c * 2, max_c * 2 + 1): # center * 2 to handle half-integers\n center = center2 / 2.0\n removals = 0\n for (r, c) in comp:\n mirror_c = int(2 * center - c)\n if (r, mirror_c) not in comp:\n removals += 1\n if removals < best_removals:\n best_removals = removals\n best_center = center\n\n if best_center is not None:\n # Remove cells without LR mirrors\n for (r, c) in comp:\n mirror_c = int(2 * best_center - c)\n if (r, mirror_c) not in comp:\n out[r][c] = bg\n\n return out\n"}