Vastly improved the solve time

We now ignore paths that have changed direction more than a threshold
number of times.