in reply to search algo to reach a number
Make a Google search on the following words: dichotomic search algorithm, binary search algorithm or half-interval search algorithm. This is likely to be your more efficient solution.
In Section
Seekers of Perl Wisdom