Skip to content

Instantly share code, notes, and snippets.

@aliwo
Created January 14, 2020 09:31
Show Gist options
  • Select an option

  • Save aliwo/2173c0a4f111f29ccfeacb2d1bc6ad3a to your computer and use it in GitHub Desktop.

Select an option

Save aliwo/2173c0a4f111f29ccfeacb2d1bc6ad3a to your computer and use it in GitHub Desktop.
class G:
pending = set()
bombed = 0
board = []
def bomb():
for i, j in reversed(sorted(G.pending)):
G.board[i].pop(j)
G.bombed += 1
G.pending = set()
def traverse(i, j):
found = False
if i >= len(G.board) - 1 or j >= len(G.board[i]) - 1 or j >= len(G.board[i+1]) - 1:
return found
if G.board[i][j] == G.board[i][j+1] == G.board[i+1][j] == G.board[i+1][j+1]:
for x, y in [(i + 1, j + 1), (i + 1, j), (i, j + 1), (i, j)]:
G.pending.add((x, y))
found = True
return found
def solution(m, n, board):
G.board = [[board[i][j] for i in reversed(range(m))] for j in range(n)]
found = True
while found:
found = False
for i in range(len(G.board) - 1):
for j in reversed(range(len(G.board[i]) - 1)):
if traverse(i, j):
found = True
bomb()
return G.bombed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment