Find all possible paths in a Matrix

1.6k Views Asked by At

I'm looking for algorithms to find all paths in a 4 x 4 matrix.
The rules are as follows

  • You can move in any direction (up, down, left, right, and diagonally)
  • The next square in the path must be a neighbour to the current square
  • Each square can only be used once
  • Each square in the path must be in the bounds of the matrix
  • No squares are restricted
  • Start squares don't matter
  • End squares don't matter

Here is an example of a valid path

\begin{array}{|r|r|r|r|} \hline & 6 & & 8 \\ \hline 5& & 7& 9 \\ \hline 3& 4& 0& \\ \hline 2& 1 & & \\ \hline \end{array}