The Challenge
Create a function that, when given an input of ASCII art (directing a path that may eventually loop), outputs the length of the loop (if there is one) and the length of the "tail" leading into the loop in one of the forms below.
Input
Your input must be passed to a function. Below is an example of a simple input.
# --> # --> #
^ |
| |
| v
# <-- #
You could visualize the above blocks like this
The "tail" is one item, while the loop is four long.
A more difficult one:
# --> # --> #
^ |
| |
| v
# --> # <-- # # --> #
^ ^ |
| | |
| | v
# --> # # <-- # <-- #
Output
You must output through STDOUT or your language's closest alternative.
Your two output integers should be the length of the tail and the length of the loop. This output can be in two forms.
- a space-delimited string:
"2 10"
- an array of integers:
[2, 10]
Rules
Every block, or
#
, will only have a single path away from itself.Every arrow is two line segments and one head.
The starting block will always be in the leftmost column.
The input will never be just a loop.
Example
# --> # --> # --> #
^ ^ |
| | |
| | v
# # <-- # <-- #
This one has a tail length of 2 and a loop length of 6. Below, the tail and loop are separated.
Tail
# -->
^
|
|
#
Loop
# --> # --> #
^ |
| |
| v
# <-- # <-- #
The correct outputs are [2, 6]
and "2 6"
.
If the input is only a tail, the loop length is zero.
# --> # --> # --> #
|
|
v
<-- # <-- #
The correct outputs for the above input are [6, 0]
and "6 0"