Guess the number/With feedback (player): Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 2,285: | Line 2,285: | ||
Congratulations! You guessed the secret number in 30 tries. |
Congratulations! You guessed the secret number in 30 tries. |
||
</pre> |
|||
=={{header|Ring}}== |
|||
<lang ring> |
|||
min = 1 |
|||
max = 100 |
|||
see "think of a number between " + min + " and " + max + nl |
|||
see "i will try to guess your number." + nl |
|||
while true |
|||
guess =floor((min + max) / 2) |
|||
see "my guess is " + guess + nl |
|||
see "is it higher than, lower than or equal to your number " give answer |
|||
ans = left(answer,1) |
|||
switch ans |
|||
on "l" min = guess + 1 |
|||
on "h" max = guess - 1 |
|||
on "e" exit |
|||
other see "sorry, i didn't understand your answer." + nl |
|||
off |
|||
end |
|||
see "goodbye." + nl |
|||
</lang> |
|||
Output: |
|||
<pre> |
|||
think of a number between 1 and 100 |
|||
i will try to guess your number. |
|||
my guess is 50 |
|||
is it higher than, lower than or equal to your number l |
|||
my guess is 75 |
|||
is it higher than, lower than or equal to your number h |
|||
my guess is 62 |
|||
is it higher than, lower than or equal to your number h |
|||
my guess is 56 |
|||
is it higher than, lower than or equal to your number l |
|||
my guess is 59 |
|||
is it higher than, lower than or equal to your number l |
|||
my guess is 60 |
|||
is it higher than, lower than or equal to your number e |
|||
goodbye. |
|||
</pre> |
</pre> |
||