Guess the number/With feedback (player): Difference between revisions
Guess the number/With feedback (player) (view source)
Revision as of 10:54, 21 April 2017
, 7 years ago→{{header|Sidef}}: updated code
m (→{{header|Sidef}}: updated code) |
|||
Line 2,730:
=={{header|Sidef}}==
<lang ruby>var min = 1
var max = 99
var tries = 0
var guess =
print <<"EOT".chomp
\n=>> Think of a number between #{min} and #{max} and I'll guess it!\n
Press <ENTER> when are you ready...
EOT
STDIN.readline
loop {
Line 2,748:
EOT
++tries
given (STDIN.readline) {
case (max <= min) {
say "\nI give up..."
break
}
when (/^h/i) {
min = guess+1
}
when (/^l/i) {
max = guess
}
when (/^e/i) {
say "\nI knew it! It took me only #{tries} tries."
break
}
default {
say "error: invalid score"
next
}
}
guess = ((min+max) // 2
}</lang>
|