Anonymous user
Guess the number/With feedback (player): Difference between revisions
Guess the number/With feedback (player) (view source)
Revision as of 22:56, 27 October 2018
, 5 years ago→with positive numbers: added/changed comments and whitespace, simplfied some statements.
No edit summary |
(→with positive numbers: added/changed comments and whitespace, simplfied some statements.) |
||
Line 2,417:
</pre>
=== with positive numbers ===
This version handles decimal fractions, the
<lang rexx>/*REXX program plays guess─the─number (with itself) with positive rational numbers. */
parse arg low high frac seed . /*obtain optional arguments from the CL*/
if
if
?= random(low, high) + random(0,fdigs) / fdigs /*Tougher game? It may have fractions.*/
$= "──────── Try to guess my number (it's between " /*part of a prompt message.*/
g=
do
if
say /*display a blank line before prompt. */
say /*display a blank line after prompt. */
g= (low + (high - low) / 2) / 1
if g=oldg then g= g + 1
say 'My guess is' g
if g=? then leave
if g>? then info= right(' Your guess is too high.', 60, "─")
else info= right(' Your guess is too low.' , 60, "─")
say info
end /*try*/
say /*stick a fork in it, we're all done. */
say 'Congratulations! You guessed the secret number in' # "tries.""</lang>
'''output''' will generally be about ten times longer (that is, has ten times the guesses) as the previous REXX version.
<pre style="height:35ex">
──────── Try to guess my number (it's between 1 and 1000 inclusive)
My guess is 500.5
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 1 and 500.5 inclusive):
My guess is 250.75
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 250.75 and 500.5 inclusive):
My guess is 375.625
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 250.75 and 375.625 inclusive):
My guess is 313.1875
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 313.1875 and 375.625 inclusive):
My guess is 344.40625
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 313.1875 and 344.40625 inclusive):
My guess is 328.796875
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 328.796875 and 344.40625 inclusive):
My guess is 336.601563
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 328.796875 and 336.601563 inclusive):
My guess is 332.699219
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 328.796875 and 332.699219 inclusive):
My guess is 330.748047
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 328.796875 and 330.748047 inclusive):
My guess is 329.772461
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 329.772461 and 330.748047 inclusive):
My guess is 330.260254
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 330.260254 and 330.748047 inclusive):
My guess is 330.504151
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 330.504151 and 330.748047 inclusive):
My guess is 330.626099
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 330.504151 and 330.626099 inclusive):
My guess is 330.565125
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 330.565125 and 330.626099 inclusive):
My guess is
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 330.595612 and 330.626099 inclusive):
My guess is
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 330.595612 and 330.610856 inclusive):
My guess is
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 330.595612 and 330.603234 inclusive):
My guess is
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 330.599423 and 330.603234 inclusive):
My guess is
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 330.599423 and 330.601329 inclusive):
My guess is
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 330.599423 and 330.600376 inclusive):
My guess is
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 330.5999 and 330.600376 inclusive):
My guess is
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 330.5999 and 330.600138 inclusive):
My guess is
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 330.5999 and 330.600019 inclusive):
My guess is
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 330.59996 and 330.600019 inclusive):
My guess is
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 330.59999 and 330.600019 inclusive):
My guess is
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 330.59999 and 330.600005 inclusive):
My guess is
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 330.599998 and 330.600005 inclusive):
My guess is
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 330.599998 and 330.600002 inclusive):
My guess is
Congratulations! You guessed the secret number in
</pre>
|