Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/24-game/Zkl/24-game.zkl
Normal file
19
Task/24-game/Zkl/24-game.zkl
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
while(1){
|
||||
digits := [1..4].pump(String,(0).random.fpM("11-",1,9));
|
||||
exp := ask("Enter an expression using the digits ",digits,
|
||||
" that evals to 24: ") - " \n";
|
||||
expf:=exp.apply(fcn(c){if ("1"<=c<="9") "(%s).toFloat()".fmt(c) else c});
|
||||
reg r;
|
||||
try { Compiler.Compiler.compileText(expf).__constructor(); r=vm.regX }
|
||||
catch { println("bad expression"); continue; }
|
||||
else{
|
||||
extra := (exp - "+-/*()" - digits);
|
||||
if (extra) { println("Extra goodies in expression: ",extra); continue; }
|
||||
(digits.split("").sort() != (exp - "+-/*()").split("").sort()) :
|
||||
if(_) { println("You can only use the digits ",digits," once each"); continue; };
|
||||
if (exp.matches("*[1-9][1-9]*"))
|
||||
{ println("no repeated digits"); continue; }
|
||||
if (r.closeTo(24,0.001)) "nice!".println();
|
||||
else println("That evaled to ",r,", not 24");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue