@StefanPochmann

This is a very concise solution.

In the output "return count(m, n, 0, 1, 1, 1, 1);" the function count doesn't have to be called with (1,1,1,1) as (i1, i2, i3, i4). Even if it called 'count(m, n, 0, a, b, c, d) with all of (a, b, c, d) being anything betwee 0 and 2 each, e.g. count(m, n, 0, 2, 3, 2, 3) it'd still be the right answer.

Correct?

Can you also comment on the complexity of this? It seems like if there are X elements in the pattern, the complexity is O( (X^n) * X) = O(X^(n+1))

( X^n refers to X next steps from any given point and that's done n times. Multiplied by X because the beginning point can be any of X elements).