kigster / minecraft

A simple interview problem with a solution

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MineGraft

This is a board of mines "." represents a cell WITHOUT a mine 1 represents a cell WITH a mine. The top left corner is 0,0. The bottom right corner is 8,8.

1.1......
....1..1.
1..1.....
....1...1
..1.1....
.1...1...
..1...1..
1..1.....
.1......1

When a mine is exploded, it blows up all the adjacent cells, including diagonals. For example, blowing up the mine A:

1.1......         
....1..1.
1..1.....
....A...1
..1.1....  
.1...1...
..1...1..
1..1.....
.1......1

Blows up all surrounding cells (B):

1.1......
....1..1.
1..BBB...
...BAB..1
..1BBB...
.1...1...
..1...1..
1..1.....
.1......1

When a mine is present in one of the adjacent cells, that mine blows up as well, triggering a chain reaction. Given this, write a method or a class that returns the coordinates of the mine that when blown up will cause the biggest chain reaction of other mines

board_string = <<-BOARD
1.1......
....1..1.
1..1.....
....1...1
..1.1....
.1...1...
..1...1..
1..1.....
.1......1
BOARD

Solution

To run this solution, save the above string into a file, or use one of the fixtures, and use the command line tool to run it:

$ bundle exec exe/minecraft spec/fixtures/mines-full.txt

minecraft

About

A simple interview problem with a solution

License:MIT License


Languages

Language:Ruby 98.3%Language:Shell 1.7%