Problem of the Day
A new programming or logic puzzle every Mon-Fri

Guessing Game

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

Permalink: http://problemotd.com/problem/guessing-game/

Comments:

Content curated by @MaxBurstein