- or download this
#!perl -l
use strict;
...
sub A{my($d,$s,$l,$y,$c,$t,$z)=@_;$c||=\$z;if(!$d){
$t+=$_ for(sort{$a<=>$b}@$y)[$l..$#$y];$$c++}else{$t+=A
($d-1,$s,$l,[@{$y||[]},$_],$c)for 1..$s}$y?$t:$t/$z}
- or download this
sub avg_roll{
...
# return the total, whatever it m
+ay be
: $total/$counter # return the average.
}
- or download this
print A(4,6,1);
print avg_roll(4,6,1);
__END__
12.2445987654321
12.2445987654321
- or download this
sub B{my($d,$s,$l,$c,@y,$t,$z)=@_;$c||=\$z;if(!$d){$t+=$_
for(sort{$a<=>$b}@y)[$l..$#y];$$c++}else{$t+=B($d-1,$s,$l,
$c,@y,$_)for 1..$s}@y?$t:$t/$z}