My previous solution to the
bonus question 2 was quite generic in terms that it can be used not only in puzzles where a single node has maximum of 2 connections, but also in cases where nodes have N connections to previous layer.
The contest puzzle can be solved faster/easier with the following algo. It is less "mathematical", but it can be easily transformed to code. Basically this algo is a representation of the steps provided by Vlad R.
1. The given puzzle is a matrix of arrows (
A). It has 12 rows (n) and 22 columns (m). Each cell of
A can take a value of: up (+1), down (-1) or null/empty (NA/0).
2. The puzzle also contains a matrix of nodes (
P). It has 13 rows (n +1) and 23 columns (m + 1). Each cell of this matrix contains a value that represents the number of paths leading to this node.
3. Each cell in the very first column of
P is eaqual to 1 representing the initial numer of paths (P
i,0 = 1).
4. Every other value of cell in
P derives from the following formula:
Pi,j = if(Ai,j-1 > 0; Pi+1,j-1) + if(Ai-1,j-1 < 0; Pi-1,j-1); *it's a bit simplified for better reading; in reality you have to check that values in
A and
P exist <=> indeces are non-negative (
i and
j >= 0)
5. That's it. The only value present in the last column will be the total number of paths leading to beta from alpha.
You can see the implementation of the algo here (excel file):
https://drive.google.com/file/d/1oYvlU0ko07NEE5G36cuYCGzhVcRo2b3Q/view?usp=sharing