Code to find shortest path through array of numbers.