Challenge
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?
Input
The input is a string of characters consisting of |
, /
, \
, D
, ^
, Y
, (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.D
marks 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.
Output
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.
Examples
Input
|
|
\
\
^
/ |
| |
\ |
\ \
\ \
\ /
Y
D
Output
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.
Input
\
|
/
|
\
|
/
D
Output
L F R F L F R
Input
/
\
/
\
^
\ \
D \
Output
R L R L R L
Other details
- 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.
Thank you!
A bit late, maybe, but UndefinedFunction is the winner coding in JavaScript! Thanks to all who entered. No other entries will be accepted.
L L
, which I think should beL L L
. The example withY
still has a1
at the end and also seems to have other errors. I read the map asF F R R R F F F R R L F
if I understand the rules correctly. \$\endgroup\$L
for the^
and twoL
for the two/
? And why did you add two moreF
to the end of theY
example? \$\endgroup\$