27
5
Time for another maze challenge, but not as you know it.
The rules for this challenge are a little different than most maze challenges. The tile types are defined as follows:
S
: The location on the maze you start atE
: The location you are trying to get to0
: Wall that you can't cross+
: Floor that you can cross
You can travel in one of six directions: up-left, up-right, left, right, down-left, or down-right.
\ /
-S-
/ \
The maze does not wrap. The goal is to find the shortest path string to get from S
to E
.
Input:
Input is space separated lines like the mazes shown. No trailing space will follow a line.
Output:
A string of R
, L
, and F
where
R
rotates you right (clockwise) 60 degreesL
rotates you left (counter clockwise) 60 degreesF
moves you one space in the direction you are pointing
You start pointing left-up
The shortest path is counted by the length of the string produced, not the number of positions visited. Your program must print the shortest path as the solution.
If the maze is unsolvable you should output Invalid maze!
.
(>>>
is the output)
0 0 0 0
0 + 0 + 0
0 0 0 + + 0
0 + 0 + 0 + 0
0 0 + + 0 0 + 0
0 0 + 0 + 0 0 + 0
E 0 + 0 0 + + 0
+ + 0 + 0 + 0
0 0 0 0 0 +
+ 0 + + +
0 S 0 0
>>>RFRFFLFLFRFFLFFFLFLFFRFLFLFRFRFRF
+ 0 0 0 0 0 0
0 0 0 0 0 + + 0
0 0 E 0 + 0 0 + 0
0 0 0 0 0 0 0 +
0 + 0 0 + + +
0 0 + + 0 0
S + 0 0 0
>>>Invalid maze!
0 E S
>>>LF
E + 0
0 + + +
0 0 S
+ +
>>>FFLF
E
0 +
0 + +
0 +
S
>>>RFFLFF
0 E + 0 0
0 + 0 0 + +
+ 0 + + + 0
+ 0 + 0 + 0
+ + + 0 S
>>>FFLFLFFRFRFFRFF
E 0 + + 0
0 + 0 + + 0
+ + + 0 + 0
+ 0 0 0 0 0
+ + + + 0
+ 0 S 0
>>>FLFFRFFRFLF
(Note that some of the mazes have other solutions that are the same length but are not listed here)
27Hoping for a Hexagony solution... – jqblz – 2015-12-01T17:10:44.880
3I'll award a 500 point bounty to a Hexagony solution. – lirtosiast – 2016-01-27T23:15:21.860
@lirtosiast2 years later, I think hexagony might be a stretch for this problem ;) – J Atkin – 2018-02-01T03:40:52.117
Let's wait for a few more years. – user202729 – 2018-02-01T10:12:12.343
Can there be a trailing newline? – user202729 – 2018-02-28T06:27:45.707
Sure. filllllleeeeerrrrrr – J Atkin – 2018-02-28T23:29:25.683
As nice as it is to be awarded a checkmark, that's not really the point of [tag:code-golf]. Can I request the other answer be reawarded the checkmark? – boboquack – 2018-06-07T03:05:42.927