13
1
Given a list of paths, output the correct path.
Example of path:
/\
----+/
|
-
and|
are horizontal and vertical paths./
and\
are 90° turns.+
is treated as a-
or a|
depending of the current direction.
Paths may go in any direction and a character may be used in multiple paths.
Input will be like this:
/--\
A------+--+--#
B------/ \--:
C------------#
D------------#
A
,B
,C
andD
are path starts#
is a wall (the path is bad):
is the end (the path is correct)
So here the output will be B
.
You can assume:
:
and#
will always be reached from the left.- The character at the right of the start of a path will always be
-
. - Paths will always be well formed.
#
and:
will always be in the same column.- There will always be only one
:
and 4 paths.
Test cases
A------#
B------#
C------#
D------:
=>
D
A-\ /---:
B-+-/ /-#
C-+---+-#
D-+---/
\-----#
=>
B
/-\
A-+\\---#
B-/\-\/-#
C----++-#
D----+/
\--:
=>
A
A-\
B-+\
C-++\/----#
D-+++//---:
\++-//--#
\+--//-#
\---/
=>
A
/-\
A-+-/-\
B-+-+-\--#
C-+-/ |/-#
D-\---++-#
\---+/
\--:
=>
B
Since this is code-golf, the shortest answer win.
Will there ever be two paths incident on the same
/
or\
? – Martin Ender – 2016-08-28T10:34:45.717@MartinEnder Yes – TuxCrafting – 2016-08-28T10:38:29.370
Oh, it's in the last test case. Might be worth mentioning explicitly. – Martin Ender – 2016-08-28T10:40:11.550
Will the
:
always be reached from the left or could it be reached from the top or bottom as well? In other words could there be characters other than#
or:
in the last column? – Martin Ender – 2016-08-28T10:53:07.123@MartinEnder
:
and#
will always be reached from the left – TuxCrafting – 2016-08-28T11:01:21.523Are the letters required to be in the left column? – feersum – 2016-08-28T11:47:30.623
@feersum Yes they are – TuxCrafting – 2016-08-28T11:53:18.943
1SILOS answer please? – Rohan Jhunjhunwala – 2016-08-28T17:07:42.890
May I assume an input that is space padded so it forms a rectangle (all lines have equal length) ? May I assume
#
and:
are always on the last column ? May I assume that the letters are always in the first column ? May I assume that the starts/goals are the only things on the last/first column (except spaces) – Ton Hospel – 2016-08-29T09:09:30.260@TonHospel 1) No 2) 3) 4) Yes – TuxCrafting – 2016-08-29T09:10:52.640