How to resolve the algorithm Guess the number/With feedback (player) step by step in the XPL0 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Guess the number/With feedback (player) step by step in the XPL0 programming language
Table of Contents
Problem Statement
Write a player for the game that follows the following rules: The computer should guess intelligently based on the accumulated scores given. One way is to use a Binary search based algorithm.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Guess the number/With feedback (player) step by step in the XPL0 programming language
Source code in the xpl0 programming language
include c:\cxpl\codes; \intrinsic 'code' declarations
int Hi, Lo, Guess;
[Text(0, "Think of a number between 1 and 100 then press a key.");
if ChIn(1) then [];
Lo:= 1; Hi:= 101;
loop [Guess:= (Lo+Hi)/2;
Text(0, "^M^JIs it "); IntOut(0, Guess);
Text(0, " (Y = yes, H = too high, L = too low)? ");
case ChIn(1) of
^L,^l: Lo:= Guess;
^H,^h: Hi:= Guess;
^Y,^y: quit
other ChOut(0, 7\bel\);
];
Text(0, "^M^JYippee!");
]
You may also check:How to resolve the algorithm String interpolation (included) step by step in the BASIC programming language
You may also check:How to resolve the algorithm Primality by trial division step by step in the SAS programming language
You may also check:How to resolve the algorithm Leap year step by step in the bc programming language
You may also check:How to resolve the algorithm Proper divisors step by step in the D programming language
You may also check:How to resolve the algorithm Bernoulli numbers step by step in the AppleScript programming language