This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,22 @@
>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

View file

@ -0,0 +1,20 @@
>try24([1,2,3,4]);
Solved the problem
6*4=24
3+3=6
1+2=3
>try24([8,7,7,1]);
Solved the problem
22+2=24
14+8=22
7+7=14
>try24([8,4,7,1]);
Solved the problem
6*4=24
7-1=6
8-4=4
>try24([3,4,5,6]);
Solved the problem
4*6=24
-1+5=4
3-4=-1