Loops and Loops and Loops 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.

# --&gt; # --&gt; #
      ^     |
      |     |
      |     v
      # &lt;-- #


You could visualize the above blocks like this



The "tail" is one item, while the loop is four long.

A more difficult one:

            # --&gt; # --&gt; #
            ^           |
            |           |
            |           v
      # --&gt; # &lt;-- #     # --&gt; #
      ^           ^           |
      |           |           |
      |           |           v
# --&gt; #           # &lt;-- # &lt;-- #




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

# --&gt; # --&gt; # --&gt; #
^     ^           |
|     |           |
|     |           v
#     # &lt;-- # &lt;-- #


This one has a tail length of 2 and a loop length of 6. Below, the tail and loop are separated.

Tail

# --&gt;
^
|
|
#


Loop

# --&gt; # --&gt; #
^           |
|           |
|           v
# &lt;-- # &lt;-- #


The correct outputs are [2, 6] and "2 6".

If the input is only a tail, the loop length is zero.

# --&gt; # --&gt; # --&gt; #
                  |
                  |
                  v
        &lt;-- # &lt;-- #


The correct outputs for the above input are [6, 0] and "6 0"
JavaScript (ES6), 221 229

A function with the input as a parameter, output as a string via popup window (alert).

Scan repeatedly the input:
at each step 


remove the end of the tail 
count the remaining '#'


When there is not more tail to remove, the number of the steps so far is the size of the tail and the number of remaining '# is the size of the loop.

All the newlines inside backticks are significant and counted

Test running the snippet below with Firefox (not Chrome, as it does not support ...)



F=s=&gt;{s=`


${s}


`.split`
`.map(r=&gt;[...r]);for(t=0,f=1;f;)s.map((r,y)=&gt;r.map((c,x)=&gt;c=='#'&amp;&amp;((r[x+2]+r[x-2]+s[y-1][x]+s[y+1][x]).match`[v&lt;&gt;^]`?++l:t+=(f=r[x-4]=r[x+4]=s[y-3][x]=s[y+3][x]=r[x]=1))),f=l=0);alert(t+' '+l)}

// Less golfed
U=s=&gt;{
  s=`\n\n\n${s}\n\n\n`.split`\n`.map(r=&gt;[...r])
  t=0
  do {
    f=l=0
    s.forEach((r,y) =&gt; {
      r.forEach((c,x) =&gt; {
        if (c == '#')
        {
          if (!(r[x+2] == '&lt;' || r[x-2] == '&gt;' || s[y-1][x] == 'v' || s[y+1][x] == '^'))
            t+=(f=r[x-4]=r[x+4]=s[y-3][x]=s[y+3][x]=r[x]=1)
          else
            ++l
        }
      })
    })
  } while(f)
  alert(t+' '+l)
}  

//Test

// Redefine console.log
alert=(...x)=&gt;O.innerHTML+=x+'\n'

test=[`
# --&gt; # --&gt; #
      ^     |
      |     |
      |     v
      # &lt;-- #`
,`
            # --&gt; # --&gt; #
            ^           |
            |           |
            |           v
      # --&gt; # &lt;-- #     # --&gt; #
      ^           ^           |
      |           |           |
      |           |           v
# --&gt; #           # &lt;-- # &lt;-- #`
,`
# --&gt; # --&gt; # --&gt; #
^     ^           |
|     |           |
|     |           v
#     # &lt;-- # &lt;-- #`      
]

test.forEach(t=&gt;(alert(t),F(t)))
&lt;pre id=O&gt;&lt;/pre&gt;