On a toroidal square grid (you can wrap around) where each cell indicates one direction (
<) if we pick a cell and start to walk following these directions, we will eventually get stuck in a loop.
We may end up in a different loop, depending on our starting cell.
Not all the cells we encounter constitute our terminal loop: these are said to be tributary to that loop.
Given a square grid configuration, count for each loop \$L_i\$:
- How many cells is it made up with? \$n_i\$
- How many tributary cells does it have? \$t_i\$
You choose the set of 4 printable characters or integers you'll use as directions.
- A square matrix having set elements as entries (can be a string)
- List of \$(n_i,t_i)\$ for each \$L_i\$
The pairs can be in any order.
6 5 2 10 2 0
Alternative inputs: 1232124421111421313441231 [[^,>,v,>,^],[>,<,<,>,^],[^,^,^,<,>],[^,v,^,v,<],[<,^,>,v,^]] Valid outputs: 2 10 2 0 6 5 (2, 10), (6, 5), (2, 0) Non valid outputs: 10 2 2 0 6 5 (0, 2), (10, 2), (6, 5)
This is code-golf, so the shortest code wins.