Problem 46603. Higher! Lower! Correct!

In he game of "Guess the number", the game leader mentally pictures a number between a lower and higher number, and then asks the contestant to guess the number. If the contestant guesses the number right, they are told "Correct!" and the game is over. If the contestant guesses wrong, they are told "Higher!" or "Lower!" and they are allowed another guess. This continues until the contestant guesses the right number.
You are asked to produce the sequence of guesses if the contestant applies the bisection strategy: they will always guess the value in the middle between the lower and upper bound (rounding down if necessary), and then update their understanding of the lower and upper bound, based on the outcome of the guesses.
This is how a game could proceed:
(Joe mentally pictures the number 18)
Joe: "Guess a number between 10 and 30."
(Sam guesses between 10 and 30)
Sam: "20"
Joe: "Lower!"
(Sam guesses between 10 and 19)
Sam: "15"
Joe: "Higher!"
(Sam guesses between 16 and 19)
Sam: "17"
Joe: "Higher!"
(Sam guesses between 18 and 19)
Sam: "18"
Joe: "Correct!"
In this case the right solution would be: guesses = [20 15 17 18];
Note: this problem is based on Problem 2635 but corrects how the upper and lower bounds are updated through the game.

Solution Stats

56.0% Correct | 44.0% Incorrect
Last Solution submitted on Aug 30, 2023

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers12

Suggested Problems

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!