• + 0 comments

    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