Guest User

arc solved by calude

a guest
Sep 14th, 2024
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. def solve_arc_challenge(grid):
  2. rows = len(grid)
  3. cols = len(grid[0])
  4. changes = 0
  5. result = [list(row) for row in grid]
  6.  
  7. def is_cornered(r, c):
  8. directions = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
  9. at_symbols = 0
  10. for dr, dc in directions:
  11. nr, nc = r + dr, c + dc
  12. if 0 <= nr < rows and 0 <= nc < cols and grid[nr][nc] == '@':
  13. at_symbols += 1
  14. return at_symbols >= 3
  15.  
  16. for r in range(rows):
  17. for c in range(cols):
  18. if grid[r][c] == 'O' and is_cornered(r, c):
  19. result[r][c] = 'X'
  20. changes += 1
  21. if changes == 3:
  22. return [''.join(row) for row in result]
  23.  
  24. return result
  25.  
  26. # Example usage
  27. input_grid = [
  28. "@@OOOOO",
  29. "O@OOOOO",
  30. "OOOOOOO",
  31. "OOOOOOO",
  32. "OOO@OOO",
  33. "OO@@OOO",
  34. "OOOOOOO"
  35. ]
  36.  
  37. output_grid = solve_arc_challenge(input_grid)
  38. for row in output_grid:
  39. print(row)
Advertisement
Add Comment
Please, Sign In to add comment