This is a solution for the HackerRank problem:
https://www.hackerrank.com/challenges/saveprincess
The file save_princess_original.rb is for the original HackerRank format, and the file save_princess.rb is a cleaned up version with tests.
The first line contains an odd integer N (3 <= N < 100) denoting the size of the grid. This is followed by an NxN grid. Each cell is denoted by '-' (ascii value: 45). The bot position is denoted by 'm' and the princess position is denoted by 'p'.
Grid is indexed using Matrix Convention
Print out the moves you will take to rescue the princess in one go. The moves must be separated by '\n', a newline. The valid moves are LEFT or RIGHT or UP or DOWN.
3
---
-m-
p--
DOWN
LEFT
This is a solution for the HackerRank problem:
https://www.hackerrank.com/challenges/saveprincess2
The file save_princess_original.rb is for the original HackerRank format, and the file save_princess.rb is a cleaned up version with tests.
The first line of the input is N (<100), the size of the board (NxN). The second line of the input contains two space separated integers, which is the position of the bot.
Grid is indexed using Matrix Convention
The position of the princess is indicated by the character 'p' and the position of the bot is indicated by the character 'm' and each cell is denoted by '-' (ascii value: 45).
Output only the next move you take to rescue the princess. Valid moves are LEFT, RIGHT, UP or DOWN
5
2 3
-----
-----
p--m-
-----
-----
LEFT
-----
-----
p-m--
-----
-----