File size: 11,954 Bytes
28aa5e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{
  "150deff5": {
    "code": "def solve(grid):\n    from itertools import combinations\n    rows = len(grid)\n    cols = len(grid[0])\n    five_cells = set()\n    for r in range(rows):\n        for c in range(cols):\n            if grid[r][c] == 5:\n                five_cells.add((r,c))\n    blocks = []\n    for r in range(rows-1):\n        for c in range(cols-1):\n            if grid[r][c]==5 and grid[r][c+1]==5 and grid[r+1][c]==5 and grid[r+1][c+1]==5:\n                blocks.append((r,c))\n    def check_remaining(cells_used):\n        remaining = five_cells - cells_used\n        if not remaining:\n            return True\n        for r,c in remaining:\n            has_neighbor = False\n            for dr,dc in [(-1,0),(1,0),(0,-1),(0,1)]:\n                if (r+dr,c+dc) in remaining:\n                    has_neighbor = True\n                    break\n            if not has_neighbor:\n                return False\n        for r,c in remaining:\n            h_nbrs = sum(1 for dc in [-1,1] if (r,c+dc) in remaining)\n            v_nbrs = sum(1 for dr in [-1,1] if (r+dr,c) in remaining)\n            if h_nbrs > 0 and v_nbrs > 0:\n                return False\n        return True\n    for size in range(len(blocks), 0, -1):\n        for combo in combinations(range(len(blocks)), size):\n            cells_used = set()\n            ok = True\n            for idx in combo:\n                r0, c0 = blocks[idx]\n                block_cells = {(r0+dr, c0+dc) for dr in range(2) for dc in range(2)}\n                if block_cells & cells_used:\n                    ok = False\n                    break\n                cells_used |= block_cells\n            if not ok:\n                continue\n            if check_remaining(cells_used):\n                result = [row[:] for row in grid]\n                for r in range(rows):\n                    for c in range(cols):\n                        if grid[r][c] == 5:\n                            result[r][c] = 8 if (r,c) in cells_used else 2\n                return result\n    result = [row[:] for row in grid]\n    for r in range(rows):\n        for c in range(cols):\n            if grid[r][c] == 5:\n                result[r][c] = 2\n    return result",
    "description": "Decompose shape of 5s into non-overlapping 2x2 blocks (colored 8) and 1-wide connecting strips (colored 2)"
  },
  "1b2d62fb": {
    "code": "def solve(grid):\n    rows = len(grid)\n    col_div = None\n    for c in range(len(grid[0])):\n        if all(grid[r][c] == 1 for r in range(rows)):\n            col_div = c\n            break\n    width = col_div\n    result = []\n    for r in range(rows):\n        row = []\n        for c in range(width):\n            left_val = grid[r][c]\n            right_val = grid[r][col_div + 1 + c]\n            row.append(8 if (left_val == 0 and right_val == 0) else 0)\n        result.append(row)\n    return result",
    "description": "Grid divided by column of 1s; output 8 where both left and right sides have 0, else 0"
  },
  "1b60fb0c": {
    "code": "def solve(grid):\n    rows = len(grid)\n    cols = len(grid[0])\n    ones = set((r,c) for r in range(rows) for c in range(cols) if grid[r][c] == 1)\n    best_center = None\n    best_additions = None\n    best_count = float('inf')\n    for cr_x2 in range(0, rows*2+1):\n        for cc_x2 in range(0, cols*2+1):\n            cr, cc = cr_x2/2.0, cc_x2/2.0\n            valid = True\n            additions = set()\n            for r,c in ones:\n                mr, mc = round(2*cr-r), round(2*cc-c)\n                if 0 <= mr < rows and 0 <= mc < cols:\n                    if (mr, mc) not in ones:\n                        if grid[mr][mc] != 0:\n                            valid = False\n                            break\n                        additions.add((mr, mc))\n                else:\n                    valid = False\n                    break\n            if valid and additions:\n                for r,c in additions:\n                    mr, mc = round(2*cr-r), round(2*cc-c)\n                    if (mr, mc) not in ones:\n                        valid = False\n                        break\n                if valid and len(additions) < best_count:\n                    best_center = (cr, cc)\n                    best_additions = additions\n                    best_count = len(additions)\n    result = [row[:] for row in grid]\n    if best_additions:\n        for r,c in best_additions:\n            result[r][c] = 2\n    return result",
    "description": "Add 2-colored cells to complete 180-degree rotational symmetry of the 1-colored shape, using the center that requires minimum additions"
  },
  "1bfc4729": {
    "code": "def solve(grid):\n    rows = len(grid)\n    cols = len(grid[0])\n    dots = []\n    for r in range(rows):\n        for c in range(cols):\n            if grid[r][c] != 0:\n                dots.append((r, c, grid[r][c]))\n    dots.sort()\n    r1, c1, color1 = dots[0]\n    r2, c2, color2 = dots[1]\n    mid = (r1 + r2) / 2.0\n    result = [[0]*cols for _ in range(rows)]\n    zone1_top = 0\n    zone1_bot = int(mid)\n    zone2_top = int(mid) + 1\n    zone2_bot = rows - 1\n    for r in range(zone1_top, zone1_bot + 1):\n        if r == zone1_top or r == r1:\n            for c in range(cols):\n                result[r][c] = color1\n        else:\n            result[r][0] = color1\n            result[r][cols-1] = color1\n    for r in range(zone2_top, zone2_bot + 1):\n        if r == r2 or r == zone2_bot:\n            for c in range(cols):\n                result[r][c] = color2\n        else:\n            result[r][0] = color2\n            result[r][cols-1] = color2\n    return result",
    "description": "Two dots split grid into top/bottom zones; each zone gets a rectangle outline with full lines at dot row and nearest grid edge"
  },
  "1caeab9d": {
    "code": "def solve(grid):\n    rows = len(grid)\n    cols = len(grid[0])\n    shapes = {}\n    for r in range(rows):\n        for c in range(cols):\n            if grid[r][c] != 0:\n                color = grid[r][c]\n                if color not in shapes:\n                    shapes[color] = [r, r, c, c]\n                else:\n                    shapes[color][0] = min(shapes[color][0], r)\n                    shapes[color][1] = max(shapes[color][1], r)\n                    shapes[color][2] = min(shapes[color][2], c)\n                    shapes[color][3] = max(shapes[color][3], c)\n    target_r = shapes[1][0]\n    height = shapes[1][1] - shapes[1][0]\n    result = [[0]*cols for _ in range(rows)]\n    for color, (min_r, max_r, min_c, max_c) in shapes.items():\n        for r in range(target_r, target_r + height + 1):\n            for c in range(min_c, max_c + 1):\n                result[r][c] = color\n    return result",
    "description": "Move all colored rectangles to align vertically with the 1-colored rectangle, keeping columns fixed"
  },
  "1f0c79e5": {
    "code": "def solve(grid):\n    rows = len(grid)\n    cols = len(grid[0])\n    cells = {}\n    for r in range(rows):\n        for c in range(cols):\n            if grid[r][c] != 0:\n                cells[(r,c)] = grid[r][c]\n    min_r = min(r for r,c in cells)\n    min_c = min(c for r,c in cells)\n    color = None\n    for v in cells.values():\n        if v != 2:\n            color = v\n            break\n    directions = []\n    for (r,c), v in cells.items():\n        if v == 2:\n            dr = r - min_r\n            dc = c - min_c\n            dir_r = 2*dr - 1\n            dir_c = 2*dc - 1\n            directions.append((dir_r, dir_c))\n    result = [[0]*cols for _ in range(rows)]\n    for dir_r, dir_c in directions:\n        k = 0\n        while True:\n            br = min_r + dir_r * k\n            bc = min_c + dir_c * k\n            any_valid = False\n            for dr in range(2):\n                for dc in range(2):\n                    r, c = br + dr, bc + dc\n                    if 0 <= r < rows and 0 <= c < cols:\n                        result[r][c] = color\n                        any_valid = True\n            if not any_valid:\n                break\n            k += 1\n    for dr in range(2):\n        for dc in range(2):\n            r, c = min_r + dr, min_c + dc\n            if 0 <= r < rows and 0 <= c < cols:\n                result[r][c] = color\n    return result",
    "description": "2x2 block with 2-colored cells indicating diagonal directions; trail the block diagonally to grid edges"
  },
  "1f642eb9": {
    "code": "def solve(grid):\n    rows = len(grid)\n    cols = len(grid[0])\n    min_r = min_c = float('inf')\n    max_r = max_c = -1\n    for r in range(rows):\n        for c in range(cols):\n            if grid[r][c] == 8:\n                min_r = min(min_r, r)\n                max_r = max(max_r, r)\n                min_c = min(min_c, c)\n                max_c = max(max_c, c)\n    result = [row[:] for row in grid]\n    for r in range(rows):\n        for c in range(cols):\n            if grid[r][c] not in (0, 8):\n                color = grid[r][c]\n                if min_c <= c <= max_c:\n                    if r < min_r:\n                        result[min_r][c] = color\n                    elif r > max_r:\n                        result[max_r][c] = color\n                elif min_r <= r <= max_r:\n                    if c < min_c:\n                        result[r][min_c] = color\n                    elif c > max_c:\n                        result[r][max_c] = color\n    return result",
    "description": "Signal dots project onto nearest edge of the 8-colored rectangular block along their row or column"
  },
  "1f876c06": {
    "code": "def solve(grid):\n    rows = len(grid)\n    cols = len(grid[0])\n    colors = {}\n    for r in range(rows):\n        for c in range(cols):\n            if grid[r][c] != 0:\n                color = grid[r][c]\n                if color not in colors:\n                    colors[color] = []\n                colors[color].append((r, c))\n    result = [row[:] for row in grid]\n    for color, positions in colors.items():\n        if len(positions) == 2:\n            (r1, c1), (r2, c2) = positions\n            dr = 1 if r2 > r1 else -1\n            dc = 1 if c2 > c1 else -1\n            r, c = r1, c1\n            while True:\n                result[r][c] = color\n                if r == r2 and c == c2:\n                    break\n                r += dr\n                c += dc\n    return result",
    "description": "Connect same-colored dot pairs with diagonal lines"
  },
  "1fad071e": {
    "code": "def solve(grid):\n    rows = len(grid)\n    cols = len(grid[0])\n    used = set()\n    n_1blocks = 0\n    for r in range(rows-1):\n        for c in range(cols-1):\n            if grid[r][c] == 1 and (r,c) not in used:\n                if grid[r][c+1]==1 and grid[r+1][c]==1 and grid[r+1][c+1]==1:\n                    n_1blocks += 1\n                    used.update([(r,c),(r,c+1),(r+1,c),(r+1,c+1)])\n    return [[1]*n_1blocks + [0]*(5-n_1blocks)]",
    "description": "Count 2x2 blocks of 1s and output that many 1s followed by 0s in a row of 5"
  },
  "2013d3e2": {
    "code": "def solve(grid):\n    rows = len(grid)\n    cols = len(grid[0])\n    min_r = min_c = float('inf')\n    max_r = max_c = -1\n    for r in range(rows):\n        for c in range(cols):\n            if grid[r][c] != 0:\n                min_r = min(min_r, r)\n                max_r = max(max_r, r)\n                min_c = min(min_c, c)\n                max_c = max(max_c, c)\n    h = max_r - min_r + 1\n    w = max_c - min_c + 1\n    half_h = h // 2\n    half_w = w // 2\n    result = []\n    for r in range(min_r, min_r + half_h):\n        row = []\n        for c in range(min_c, min_c + half_w):\n            row.append(grid[r][c])\n        result.append(row)\n    return result",
    "description": "Extract the top-left quadrant of the symmetric pattern in the grid"
  }
}