Bowie's in a maze
Imagine you're in your house one night, minding your own business, when suddenly your little brother disappears. Right then, David Bowie shows up and wisks you off to a gigantic maze. He tells you if you don't solve the maze as fast as possible, your brother will turn into a muppet.
It's cool, you tell yourself. This isn't actually 1986. You have Google Maps. So you load up your phone and get a map.
Given a map of a maze in the following format, find the shortest route from start to finish in the least amount of time possible. If it helps, every test case you will be given will have exactly one possible solution description.
Maps are simply grids given to you as newline-delimited rows consisting of four
different types of characters. A cell can either be
a row ends with a
Smeans start, this is your starting cell. There will only be one of these.
Fmeans finish, this is where you are trying to get to. There will also only be one of these.
-is a navigable cell. You can move to it if it is horizontally or vertically adjacent to your current cell (no diagonal moves).
Xis a filled cell, you can't move here.
The map will be delivered over standard in, and standard in will be closed when the map is over.
---- SXX- XF--
Once you've figured out the shortest path, your program needs to tell someone.
Your program should use a string of characters representing steps for your
path, newline separated. A step can either be
Nmeans north, go up on the map representation.
Smeans south, go down.
Emeans east, go right.
Wmeans west, go left.
For the previous example map, the example output should be:
N E E E S S W W