What is this Strange Behavior of the Optimal Guess in Hi Lo?
Your code is correct in a theoretical sense, but it runs into issues when dealing with very precise floating point comparisons.
If you instead store the total number of guesses required for your strategy to work for every possible case (instead of computing the average case), you can use integers and avoid this issue.
All that's required for this method is changing line 13 to output (3,[1,2]), line 14 to be something large (try n*n), and change line 22 to be e=le+re+n
.
Once those changes have been made, the valid initial guesses become a continuous range with no gaps.