RosettaCodeData/Task/24-game-Solve/Euler-Math-Toolbox/24-game-solve-1.euler
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

22 lines
561 B
Text

>function try24 (v) ...
$n=cols(v);
$if n==1 and v[1]~=24 then
$ "Solved the problem",
$ return 1;
$endif
$loop 1 to n
$ w=tail(v,2);
$ loop 1 to n-1
$ h=w; a=v[1]; b=w[1];
$ w[1]=a+b; if try24(w); ""+a+"+"+b+"="+(a+b), return 1; endif;
$ w[1]=a-b; if try24(w); ""+a+"-"+b+"="+(a-b), return 1; endif;
$ w[1]=a*b; if try24(w); ""+a+"*"+b+"="+(a*b), return 1; endif;
$ if not b~=0 then
$ w[1]=a/b; if try24(w); ""+a+"/"+b+"="+(a/b), return 1; endif;
$ endif;
$ w=rotright(w);
$ end;
$ v=rotright(v);
$end;
$return 0;
$endfunction