in reply to Updates to a guessing number script
Seems like the fewest # of guesses would use a splitting algorithm where you take the possible range and guess the # in the middle. For example, the user chooses 2. You start out with a possible range of 1-10 and program finds the average (1 + 10) / 2 = 5.5 and chooses 6. User says 'lower' and the program updates the range to be 1-5 and guesses 3. User says 'lower', so new range is 1-2 and program guesses 2. In order to implement this, you can just keep track of the upper and lower bounds of the range and adjust the appropriate boundary for each iteration.
|