You've given a map to a friend that looks a bit like this:
| / | / | \ | \ D
A simple map that starts at the top and ends at the bottom. Sadly, your friend doesn't get it. Can you decode the map so that he can read it?
The input is a string of characters consisting of
(space), and newlines.
|tells to stay in the same column.
\tells to move to the column to the right and down 1.
/tells to move to the column to the left and down 1.
Dmarks the destination.
^(if present) tells of a split in the path.
Y(if present) tells of a rejoining of paths. Treat it like a
The input will be arranged so that it makes a kind of path:
| | \ | ^ / \ / | D |
There will always be a space between two paths, and all paths will either rejoin or reach the last line of the input. There will only be one split per map. There is no limit to the length of the input map. There will never be more than two paths.
The output should be a string of directions.
- "L" should tell your friend to move Left and take 1 step forward.
- "R" should tell your friend to move Right and take 1 step forward.
- "F" should tell your friend to move 1 step forward.
For the input example map, the output would be as follows:
F F L F R R R
Note that your friend is starting at the top of the map and facing down the map. Give the directions from his perspective.
For an instance of "^", your program must be able to choose the path that leads to the destination (D). If the two paths recombine, your program must choose the straightest path (the one with the most
|s) to follow.
Directions must be separated by spaces, and must end on D.
| | \ \ ^ / | | | \ | \ \ \ \ \ / Y D
F F L L L F F F L L R F
Since the leftmost path contains only 1
|, we use the rightmost path that has 3.
\ | / | \ | / D
L F R F L F R
/ \ / \ ^ \ \ D \
R L R L R L
- This is code golf, so the person with the shortest code by next Wednesday, the 19th of August, wins.
- Constructive feedback welcome and greatly appreciated.
- Partially inspired by A Map to Hidden Treasure
- Feel free to change the title to something more creative.
- If you find mistakes that I made, correct them.
- And of course, have fun.