Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def solve_arc_challenge(grid):
- rows = len(grid)
- cols = len(grid[0])
- changes = 0
- result = [list(row) for row in grid]
- def is_cornered(r, c):
- directions = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
- at_symbols = 0
- for dr, dc in directions:
- nr, nc = r + dr, c + dc
- if 0 <= nr < rows and 0 <= nc < cols and grid[nr][nc] == '@':
- at_symbols += 1
- return at_symbols >= 3
- for r in range(rows):
- for c in range(cols):
- if grid[r][c] == 'O' and is_cornered(r, c):
- result[r][c] = 'X'
- changes += 1
- if changes == 3:
- return [''.join(row) for row in result]
- return result
- # Example usage
- input_grid = [
- "@@OOOOO",
- "O@OOOOO",
- "OOOOOOO",
- "OOOOOOO",
- "OOO@OOO",
- "OO@@OOO",
- "OOOOOOO"
- ]
- output_grid = solve_arc_challenge(input_grid)
- for row in output_grid:
- print(row)
Advertisement
Add Comment
Please, Sign In to add comment