by igor47 · 13y ago · 0 comments
https://gist.github.com/alexchow/7228746
Try the case: ([2,5,1,2,3,4,7,7,6,3,5], 12)
The issue with this "state machine" approach is you don't have "lookahead".
In the two pass approach (approach from one side, then the other), you essentially have two machines, one implicitly serving as the "lookahead" for the other.
not in response to the author!
MISMATCH: [6, 7, 7, 4, 3, 2, 1, 5, 2] holds 10 (got 0) MISMATCH: [5, 3, 6, 7, 7, 4, 3, 2, 1, 5, 2] holds 12 (got 2)
Another mismatch: MISMATCH: [2, 0, 1] holds 1 (got 0) TRUE: [1, 0, 2] holds 1