The current implementation is subject to rounding error and may be stuck in an infinite loop looking always at the same element.
One option is to always reduce the search space by removing the last guess from the search space.
Created attachment 583705 [details] [diff] [review]
Comment on attachment 583705 [details] [diff] [review]
Thanks, appears to fix my testcase.