Use recursive functions to find paths in a matrix