Hello sweet sweet Monday!
Let's start the week off with a programming challenge. Today's problem will be to create a game that guesses the number you're thinking of. The program will ask you to think of a number [1-100] and will be allowed 6 yes or no questions. Most questions will probably be of the form "is your number higher/lower than x". After asking 6 questions the program should take a guess. Here is an example where the game wins in 5 questions.
> Think of a number [1-100] > Is it greater than 20? y > Is it greater than 30? n > Is it greater than 25? n > Is it greater than 22 y > Is it greater than 24? y > Is your number 25? y
Comments:
Eddy - 9 years, 11 months ago
My solution in C. Using either random numbers or binary search/halving.
reply permalink