Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
42
Task/24-game/XPL0/24-game.xpl0
Normal file
42
Task/24-game/XPL0/24-game.xpl0
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
real Stack(10), A, B;
|
||||
int SP, I, Char, Digit, Digits(10);
|
||||
|
||||
proc Push(X);
|
||||
real X;
|
||||
[Stack(SP):= X; SP:= SP+1];
|
||||
|
||||
func real Pop;
|
||||
[SP:= SP-1; return Stack(SP)];
|
||||
|
||||
[SP:= 0;
|
||||
for I:= 0 to 9 do Digits(I):= 0;
|
||||
Text(0, "Enter an RPN expression that equals 24 using all these digits:");
|
||||
for I:= 0 to 3 do
|
||||
[Digit:= Ran(9)+1;
|
||||
ChOut(0, ^ ); ChOut(0, Digit+^0);
|
||||
Digits(Digit):= Digits(Digit)+1;
|
||||
];
|
||||
Text(0, "^m^j> ");
|
||||
loop [Char:= ChIn(1);
|
||||
ChOut(0, Char);
|
||||
if Char >= ^1 and Char <=^9 then
|
||||
[Digit:= Char - ^0;
|
||||
Push(float(Digit));
|
||||
Digits(Digit):= Digits(Digit) - 1;
|
||||
]
|
||||
else [if SP >= 2 then [A:= Pop; B:= Pop] else quit;
|
||||
case Char of
|
||||
^+: Push(B+A);
|
||||
^-: Push(B-A);
|
||||
^*: Push(B*A);
|
||||
^/: Push(B/A)
|
||||
other quit;
|
||||
];
|
||||
];
|
||||
CrLf(0);
|
||||
for I:= 0 to 9 do
|
||||
if Digits(I) # 0 then
|
||||
[Text(0, "Must use each of the given digits.^m^j"); exit];
|
||||
Text(0, if abs(Pop-24.0) < 0.001 then "Correct!" else "Wrong.");
|
||||
CrLf(0);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue