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.
defbomberMan(n,grid):ifn==1:#No changesreturngridifn%2==0:#All spaces have bombsreturn["O"*cfor_inrange(r)]pattern=re.compile(r'(?=O)')#There are two patterns for each odd number after 1#Pattern is determined by "(n//2) % 2"for_inrange(2-(n//2)%2):detonations=set()#Get the locations of the detonationsformatchinpattern.finditer("\n".join(grid)):y=match.start()//(c+1)x=match.start()%(c+1)detonations.add((y,x))ify!=0:detonations.add((y-1,x))ify!=r-1:detonations.add((y+1,x))ifx!=0:detonations.add((y,x-1))ifx!=c-1:detonations.add((y,x+1))grid=[""for_inrange(r)]foryinrange(r):forxinrange(c):if(y,x)indetonations:grid[y]+="."else:grid[y]+="O"returngrid
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 →
Python 3