| { | |
| "017c7c7b": { | |
| "code": "def solve(grid):\n rows = len(grid)\n cols = len(grid[0])\n target_rows = rows + rows // 2\n def find_period(seq):\n n = len(seq)\n for p in range(1, n+1):\n valid = True\n for i in range(n):\n if seq[i] != seq[i % p]:\n valid = False\n break\n if valid:\n return p\n return n\n result = [[0] * cols for _ in range(target_rows)]\n for c in range(cols):\n col_vals = [grid[r][c] for r in range(rows)]\n period = find_period(col_vals)\n for r in range(target_rows):\n val = col_vals[r % period]\n result[r][c] = 2 if val == 1 else val\n return result", | |
| "description": "Extend periodic column patterns from 6 to 9 rows, replacing 1 with 2" | |
| }, | |
| "025d127b": { | |
| "code": "def solve(grid):\n rows = len(grid)\n cols = len(grid[0])\n result = [[0]*cols for _ in range(rows)]\n color_cells = {}\n for r in range(rows):\n for c in range(cols):\n v = grid[r][c]\n if v != 0:\n if v not in color_cells:\n color_cells[v] = []\n color_cells[v].append((r, c))\n for color, cells in color_cells.items():\n bottom_row = max(r for r, c in cells)\n max_col = max(c for r, c in cells)\n for r, c in cells:\n if r == bottom_row:\n result[r][c] = color\n else:\n new_c = c + 1 if c + 1 <= max_col else c\n result[r][new_c] = color\n return result", | |
| "description": "Shift parallelogram shapes right by 1 except bottom row, capped at max column" | |
| }, | |
| "05269061": { | |
| "code": "def solve(grid):\n rows = len(grid)\n cols = len(grid[0])\n color_map = {}\n for r in range(rows):\n for c in range(cols):\n if grid[r][c] != 0:\n key = (r + c) % 3\n color_map[key] = grid[r][c]\n result = [[0]*cols for _ in range(rows)]\n for r in range(rows):\n for c in range(cols):\n result[r][c] = color_map[(r + c) % 3]\n return result", | |
| "description": "Fill grid with 3-color repeating diagonal stripe pattern based on (row+col) mod 3" | |
| }, | |
| "05f2a901": { | |
| "code": "def solve(grid):\n rows = len(grid)\n cols = len(grid[0])\n cells_8 = []\n cells_2 = []\n for r in range(rows):\n for c in range(cols):\n if grid[r][c] == 8:\n cells_8.append((r, c))\n elif grid[r][c] == 2:\n cells_2.append((r, c))\n r8_min = min(r for r,c in cells_8)\n r8_max = max(r for r,c in cells_8)\n c8_min = min(c for r,c in cells_8)\n c8_max = max(c for r,c in cells_8)\n r2_min = min(r for r,c in cells_2)\n r2_max = max(r for r,c in cells_2)\n c2_min = min(c for r,c in cells_2)\n c2_max = max(c for r,c in cells_2)\n r8_center = (r8_min + r8_max) / 2\n c8_center = (c8_min + c8_max) / 2\n r2_center = (r2_min + r2_max) / 2\n c2_center = (c2_min + c2_max) / 2\n row_overlap = not (r2_max < r8_min or r2_min > r8_max)\n col_overlap = not (c2_max < c8_min or c2_min > c8_max)\n dr = 0\n dc = 0\n if col_overlap and not row_overlap:\n if r2_center < r8_center:\n dr = r8_min - r2_max - 1\n else:\n dr = r8_max - r2_min + 1\n elif row_overlap and not col_overlap:\n if c2_center < c8_center:\n dc = c8_min - c2_max - 1\n else:\n dc = c8_max - c2_min + 1\n else:\n row_dist = abs(r2_center - r8_center)\n col_dist = abs(c2_center - c8_center)\n if row_dist > col_dist:\n if r2_center < r8_center:\n dr = r8_min - r2_max - 1\n else:\n dr = r8_max - r2_min + 1\n else:\n if c2_center < c8_center:\n dc = c8_min - c2_max - 1\n else:\n dc = c8_max - c2_min + 1\n result = [[0]*cols for _ in range(rows)]\n for r, c in cells_8:\n result[r][c] = 8\n for r, c in cells_2:\n result[r + dr][c + dc] = 2\n return result", | |
| "description": "Slide red(2) shape to be adjacent to gray(8) anchor block" | |
| }, | |
| "0962bcdd": { | |
| "code": "def solve(grid):\n rows = len(grid)\n cols = len(grid[0])\n result = [row[:] for row in grid]\n for r in range(rows):\n for c in range(cols):\n if grid[r][c] == 0:\n continue\n center_color = grid[r][c]\n if r > 0 and r < rows-1 and c > 0 and c < cols-1:\n up = grid[r-1][c]\n down = grid[r+1][c]\n left = grid[r][c-1]\n right = grid[r][c+1]\n if up == down == left == right and up != 0 and up != center_color:\n arm_color = up\n for dr, dc in [(-2,0),(2,0),(0,-2),(0,2)]:\n nr, nc = r+dr, c+dc\n if 0 <= nr < rows and 0 <= nc < cols:\n result[nr][nc] = arm_color\n for dr, dc in [(-1,-1),(-1,1),(1,-1),(1,1)]:\n nr, nc = r+dr, c+dc\n if 0 <= nr < rows and 0 <= nc < cols:\n result[nr][nc] = center_color\n for dr, dc in [(-2,-2),(-2,2),(2,-2),(2,2)]:\n nr, nc = r+dr, c+dc\n if 0 <= nr < rows and 0 <= nc < cols:\n result[nr][nc] = center_color\n return result", | |
| "description": "Expand cross patterns: extend arms by 1, add center color at diagonal positions" | |
| }, | |
| "10fcaaa3": { | |
| "code": "def solve(grid):\n h = len(grid)\n w = len(grid[0])\n oh, ow = 2*h, 2*w\n color_map = {}\n for r in range(h):\n for c in range(w):\n if grid[r][c] != 0:\n color_map[(r, c)] = grid[r][c]\n result = [[0]*ow for _ in range(oh)]\n tiled_colored = set()\n for (r, c), v in color_map.items():\n for tr in range(2):\n for tc in range(2):\n nr, nc = r + tr*h, c + tc*w\n result[nr][nc] = v\n tiled_colored.add((nr, nc))\n for cr, cc in tiled_colored:\n for dr, dc in [(-1,-1),(-1,1),(1,-1),(1,1)]:\n nr, nc = cr+dr, cc+dc\n if 0 <= nr < oh and 0 <= nc < ow and result[nr][nc] == 0:\n result[nr][nc] = 8\n return result", | |
| "description": "Tile input 2x2 and place 8s at diagonal neighbors of colored cells" | |
| }, | |
| "11852cab": { | |
| "code": "def solve(grid):\n rows = len(grid)\n cols = len(grid[0])\n result = [row[:] for row in grid]\n non_zero = {}\n for r in range(rows):\n for c in range(cols):\n if grid[r][c] != 0:\n non_zero[(r,c)] = grid[r][c]\n if not non_zero:\n return result\n all_r = [r for r,c in non_zero]\n all_c = [c for r,c in non_zero]\n center_r = (min(all_r) + max(all_r)) / 2\n center_c = (min(all_c) + max(all_c)) / 2\n for (r, c), val in non_zero.items():\n dr = r - center_r\n dc = c - center_c\n rotations = [\n (center_r - dc, center_c + dr),\n (center_r - dr, center_c - dc),\n (center_r + dc, center_c - dr),\n ]\n for nr, nc in rotations:\n nr, nc = int(round(nr)), int(round(nc))\n if 0 <= nr < rows and 0 <= nc < cols and result[nr][nc] == 0:\n result[nr][nc] = val\n return result", | |
| "description": "Complete 4-fold rotational symmetry of diamond/cross pattern" | |
| }, | |
| "1190e5a7": { | |
| "code": "def solve(grid):\n rows = len(grid)\n cols = len(grid[0])\n sep = None\n for r in range(rows):\n if len(set(grid[r])) == 1:\n sep = grid[r][0]\n break\n bg = None\n for r in range(rows):\n for c in range(cols):\n if grid[r][c] != sep:\n bg = grid[r][c]\n break\n if bg is not None:\n break\n sep_rows = []\n for r in range(rows):\n if all(grid[r][c] == sep for c in range(cols)):\n sep_rows.append(r)\n sep_cols = []\n for c in range(cols):\n if all(grid[r][c] == sep for r in range(rows)):\n sep_cols.append(c)\n all_rows = sorted(set([-1] + sep_rows + [rows]))\n all_cols = sorted(set([-1] + sep_cols + [cols]))\n n_row_bands = sum(1 for i in range(len(all_rows)-1) if all_rows[i+1] - all_rows[i] - 1 > 0)\n n_col_bands = sum(1 for i in range(len(all_cols)-1) if all_cols[i+1] - all_cols[i] - 1 > 0)\n return [[bg] * n_col_bands for _ in range(n_row_bands)]", | |
| "description": "Count number of row and column bands in grid divided by separator lines, output grid of that size" | |
| }, | |
| "137eaa0f": { | |
| "code": "def solve(grid):\n rows = len(grid)\n cols = len(grid[0])\n result = [[0, 0, 0], [0, 5, 0], [0, 0, 0]]\n fives = []\n for r in range(rows):\n for c in range(cols):\n if grid[r][c] == 5:\n fives.append((r, c))\n for fr, fc in fives:\n for dr in range(-2, 3):\n for dc in range(-2, 3):\n nr, nc = fr + dr, fc + dc\n if 0 <= nr < rows and 0 <= nc < cols:\n val = grid[nr][nc]\n if val != 0 and val != 5:\n or_, oc = 1 + dr, 1 + dc\n if 0 <= or_ < 3 and 0 <= oc < 3:\n result[or_][oc] = val\n return result", | |
| "description": "Assemble colored fragments around 5-marked centers into a 3x3 output grid" | |
| }, | |
| "09629e4f": { | |
| "code": "def solve(grid):\n rows = len(grid)\n cols = len(grid[0])\n key_br = key_bc = None\n for br in range(3):\n for bc in range(3):\n rs, cs = br * 4, bc * 4\n has8 = False\n for r in range(3):\n for c in range(3):\n if grid[rs + r][cs + c] == 8:\n has8 = True\n if not has8:\n key_br, key_bc = br, bc\n krs, kcs = key_br * 4, key_bc * 4\n key_grid = [[grid[krs + r][kcs + c] for c in range(3)] for r in range(3)]\n result = [[0] * cols for _ in range(rows)]\n for r in range(rows):\n for c in range(cols):\n if grid[r][c] == 5:\n result[r][c] = 5\n for br in range(3):\n for bc in range(3):\n rs, cs = br * 4, bc * 4\n fill_val = key_grid[br][bc]\n for r in range(3):\n for c in range(3):\n result[rs + r][cs + c] = fill_val\n return result", | |
| "description": "Find the 3x3 block missing color 8, use its contents as a template to fill all blocks uniformly" | |
| } | |
| } |