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.
funcbomberMan(n:Int,grid:[String])->[String]{// Write your code here varcurrentGrid:[[UInt8]]=grid.map{[UInt8]($0.utf8)}varresults:[[[UInt8]]]=[currentGrid]letresultIndex:Int=abs((n%4)-1)letallBombs:[[UInt8]]=[[UInt8]](repeating:[UInt8](repeating:79,count:currentGrid.first!.count),count:currentGrid.count)ifn==1{returngrid}ifresultIndex%2==1{returnallBombs.map{String(bytes:$0,encoding:String.Encoding.utf8)!}}while(true){varresult:[[UInt8]]=allBombsforindex1in0...currentGrid.count-1{forindex2in0...currentGrid[index1].count-1{ifcurrentGrid[index1][index2]==79{ifindex2-1>=0{result[index1][index2-1]=46}ifindex2+1<=currentGrid[index1].count-1{result[index1][index2+1]=46}ifindex1>0{result[index1-1][index2]=46}ifindex1+1<=currentGrid.count-1{result[index1+1][index2]=46}result[index1][index2]=46}}}ifresults.firstIndex(where:{$0==result})!=nil{break}results.append(result)currentGrid=result}ifresults.count>2{results.removeFirst()results.swapAt(0,1)}returnresults[resultIndex/2].map{String(bytes:$0,encoding:String.Encoding.utf8)!}}
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 →
swift: