Tag Archives: hackerrank

How I solved Bomberman challenge on HackerRank

I found a challenge called “The Bomberman Game” on HackerRank and I found it pretty interesting.

It boils down to something like this:

The Bomberman Game

Rules

  • Bombs will explode in 3 seconds
  • When a bomb explodes it clears its tile and 1 tile up, down, left, right
  • Bombs that are about to go off explode at the same time
  • There are no chain reactions
  • If a bomb explodes next to another that is not about to go off then the nearby bomb is just cleared

Iteration

  1. Bomberman plants some bombs (you’re given an input with the map)
  2. A second passes
  3. A second passes. Bomberman plants bombs on all empty slots
  4. A second passes
  5. Repeat 3 and 4 until N seconds passes

Input

  • R = number of rows
  • C = number of cols
  • S = number of seconds
  • O = bomb
  • . = empty
R C S
O..
...

Task

Return the map after N seconds have passed.


Solving

The first thing I though was to solve it with a generator (well, there was no real need to use it, but since it is about a game I thought it would be fun to be able to access any state of the game).

Continue reading

Advertisements