We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def bomberMan(n, grid):
if n% 2 == 0:
return ["O"*len(grid[0])]*len(grid)
k = 1 if (n-1)% 4 != 0 else (0 if n==1 else 2)
for _ in range(k):
d1 = []
d2 = []
grid_2 = [''.join(x) for x in zip(*grid)]
for nap, dn in ((grid, d1), (grid_2, d2)):
for i in nap:
gr = i.replace(".", '0').replace("O", '1')
gr2 = int(gr, 2) | int(gr, 2) <<1
gr3 = int(gr +'0', 2) | gr2 >>1
dn.append(bin(gr3)[2:].zfill(len(i) + 1)[1:])
d3 = [''.join(x) for x in zip(*d2)]
d4 = [(int(p, 2) | int(v, 2)) for (p, v) in zip(d1, d3)]
d4s = [bin(x + 2 ** len(grid[0]))[3:] for x in d4]
grid = [i.replace("0", "O").replace("1", ".") for i in d4s]
return grid
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Bomberman Game
You are viewing a single comment's thread. Return to all comments →
def bomberMan(n, grid): if n% 2 == 0: return ["O"*len(grid[0])]*len(grid)