Guess the number/With feedback (player): Difference between revisions
Content added Content deleted
(Added Kotlin) |
(Added Algol 68) |
||
Line 47: | Line 47: | ||
Guess_Number (Lower_Limit, Upper_Limit); |
Guess_Number (Lower_Limit, Upper_Limit); |
||
end Guess_Number_Player;</lang> |
end Guess_Number_Player;</lang> |
||
=={{header|ALGOL 68}}== |
|||
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}} |
|||
<lang algol68>BEGIN |
|||
INT lower := 1; |
|||
INT upper := 100; |
|||
print( ( "Think of a number between ", whole( lower, 0 ), " and ", whole( upper, 0 ), newline ) ); |
|||
print( ( "Please enter Y if I guess correctly, L is it is lower, G if it is greater or Q if you've had enough", newline ) ); |
|||
WHILE |
|||
INT mid = lower + ( ( upper - lower ) OVER 2 ); |
|||
CHAR reply; |
|||
WHILE |
|||
print( ( "Is it ", whole( mid, 0 ), "? Y/L/G/Q: " ) ); |
|||
read( ( reply, newline ) ); |
|||
NOT char in string( reply, NIL, "YLGQylgq" ) |
|||
DO SKIP OD; |
|||
IF reply = "Q" OR reply = "q" OR reply = "Y" OR reply = "y" |
|||
THEN FALSE |
|||
ELIF lower >= upper THEN |
|||
print( ( "Based on your answers so far, it must be ", whole( lower, 0 ), newline ) ); |
|||
FALSE |
|||
ELSE |
|||
IF reply = "L" OR reply = "l" THEN upper := mid - 1 |
|||
ELIF reply = "G" OR reply = "g" THEN lower := mid + 1 |
|||
FI; |
|||
TRUE |
|||
FI |
|||
DO SKIP OD |
|||
END</lang> |
|||
=={{header|AppleScript}}== |
=={{header|AppleScript}}== |