Welcome to the Treehouse Community
Looking to learn something new?
Alexander Gyger14,237 Points
How to prevent the program from guessing the same wrong number multiple times?
Maybe it's a bit out of scope for this exercise, but when I ran this random guessing program and printed out the attempts to the console, i got this: 1434 attempt - guess: 764 app.js:21:3 1449 attempt - guess: 764 app.js:21:3
So it guessed the wrong number 764 at least twice, and other wrong numbers probably as well.
If this was a competitive program to guess numbers, this would be quite ineffective. To make it better it would have to be able to consider all prior wrong guesses.
How would one approach that? With storing and recalling? Or would that make the program slower?
pooya tolideh12,184 Points
One quick way to tackle this is to write an algorithm like the colder-hotter game.
If the guess is more than the number you have in mind, you create a new range with the guess as upper limit If the guess is less than the target, then you need to recreate the range and set the guess as lower limit.