Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Beat you - 24 permutations (if my Perl hash can count right.)
code:
use strict; my %d;
&a(1,2,3,4); print scalar (keys %d) ."\n"; foreach my $x (sort keys %d) { print "$x\n"; }
sub a($a,$b,$c,$d) { my ($a,$b,$c,$d)=@_; my $z; for (my $i = 1; $i <=4; $i++) { for (my $j = 1; $j <=6; $j++) { for (my $k = 1; $k <=4; $k++) { $d{"$a,$b,$c,$d"}=1; $z = $b; $b = $c; $c = $d; $d = $z; } $z = $a; $a = $b; $b = $z; } $z = $c; $c = $d; $d = $z; } }
c:\data\scripts>junk.pl 24 1,2,3,4 1,2,4,3 1,3,2,4 1,3,4,2 1,4,2,3 1,4,3,2 2,1,3,4 2,1,4,3 2,3,1,4 2,3,4,1 2,4,1,3 2,4,3,1 3,1,2,4 3,1,4,2 3,2,1,4 3,2,4,1 3,4,1,2 3,4,2,1 4,1,2,3 4,1,3,2 4,2,1,3 4,2,3,1 4,3,1,2 4,3,2,1
code:
function game24($a,$b,$c,$d)
Dim $h, $j, $l, $p, $q, $r, $s, $t, $v, $, $x, $y, $z $h = "+","-","/","*" for $z=1 to 4 for $y=1 to 6 for $x=1 to 4 for each $p in $h for each $q in $h for each $r in $h for each $j in split("0,8~0,8,10,18~0,12~4,16","~") $ = ".0" $s = ""+$a+$+$p+$b+$+$q+$c+$+$r+$d+$ for each $ in split($j,",") $l = chr(40 + ($l="(")) $s = "" + left($s,$) + $l + substr($s,1+$) next $t = execute("$$v=$s") if abs($v-24)< 1E-9 goto E endif next next next next $ = $b $b = $c $c = $d $d = $ next $ = $a $a = $b $b = $ next $ = $c $c = $d $d = $ next $s = ""
:E $game24 = $s exit endfunction
[ 24. September 2002, 02:53: Message edited by: Howard Bullock ]
|