19 lines
869 B
Text
19 lines
869 B
Text
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");
|
|
}
|
|
}
|