Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Updates to a guessing number script

by frozenwithjoy (Priest)
on Feb 28, 2014 at 22:47 UTC ( [id://1076627]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1076627]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-19 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found