4 kyu

Escape the maze

27 of 904cyril-lemaire

Description:

That's terrible! Some evil korrigans have abducted you during your sleep and threw you into a maze of thorns in the scrubland D:
But have no worry, as long as you're asleep your mind is floating freely in the sky above your body.

Seeing the whole maze from above in your sleep, can you remember the list of movements you'll have to do to get out when you awake?


Input


You are given the whole maze maze as a 2D grid, more specifically in your language:

an array of strings

maze[0][0] is the top left-hand corner

maze[maze.length - 1][maze[0].length - 1] is the bottom right-hand corner

Inside this 2D grid:

  • ' ' is some walkable space
  • '#' is a thorn bush (you can't pass through)
  • '^', '<', 'v' or '>' is your sleeping body facing respectively the top, left, bottom or right side of the map.

Output


Write the function escape that returns the list/array of moves you need to do relatively to the direction you're facing in order to escape the maze (you won't be able to see the map when you wake up). as an array of the following instructions:

  • 'F' move one step forward
  • 'L' turn left
  • 'R' turn right
  • 'B' turn back

    Note: 'L','R', and 'B' ONLY perform a rotation and will not move your body

If the maze has no exit, return an empty array.

  • This is a real maze, there is no "escape" point. Just reach the edge of the map and you're free!
  • You don't explicitely HAVE to find the shortest possible route, but you're quite likely to timeout if you don't ;P
  • Aside from having no escape route the mazes will all be valid (they all contain one and only one "body" character and no other characters than the body, "#" and " ". Besides, the map will always be rectangular, you don't have to check that either)
Fundamentals
Algorithms

Similar Kata:

Stats:

CreatedJan 12, 2017
PublishedMar 1, 2017
Warriors Trained9340
Total Skips3491
Total Code Submissions14410
Total Times Completed904
Ruby Completions27
JavaScript Completions293
Python Completions410
Java Completions112
C Completions84
Total Stars487
% of votes with a positive feedback rating96% of 271
Total "Very Satisfied" Votes252
Total "Somewhat Satisfied" Votes17
Total "Not Satisfied" Votes2
Total Rank Assessments3
Average Assessed Rank
4 kyu
Highest Assessed Rank
3 kyu
Lowest Assessed Rank
5 kyu
Ad
Contributors
  • cyril-lemaire Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • kontic Avatar
Ad