guessing-game
guessing-game copied to clipboard
fix: provide correct tests to correspond to reference implementation of binary search
Supplied tests fail when reference implementation of binary search is tested against them. By reference implementation I mean binary search algorithm described in Wikipedia:
https://en.wikipedia.org/wiki/Binary_search_algorithm
Another example of reference implementation of binary search algorithm from the book McMillan - Data Structures & Algorithms with JavaScript (2014)
Reference algorithm highlights:
- guess = Math.floor((range_start + range_end) / 2);
- if secret number is lower: range_end = attempt - 1;
- if secret number is higher: range_start = attempt + 1;
We need this fix because the old tests are designed for the wrong solution (where we can't reach the lower value of range)
I suffered incredibly for an hour without this correction. It is necessary for the correct algorithm!