Newb ??
Steven D'Aprano
steve at REMOVETHIScyber.com.au
Thu Nov 10 17:36:54 EST 2005
On Thu, 10 Nov 2005 17:31:18 +0000, Steve Holden wrote:
> Effectively you want to start with a minposs and maxposs, which are set
> to 0 and 100 respectively. Your guess should bisect the range (as nearly
> as it can given that you are dealing with integers, and you have to be
> careful to get the awkward boundary conditions right). So your first
> guess will be 50. If your guess is too low then replace minposs with
> your guess (in this case 50); if too high, replace maxposs with your
> guess; loop to generate the next guess, and so on. In practice since
> log2(100) > 5 your five guesses won't always be enough (though seven
> should be).
Dude, that's what my code does, although I admit I took zero care to get
the awkward boundary conditions right, nor did I put code in to stop the
game after five attempts.
--
Steven.
More information about the Python-list
mailing list