for (1..13){ my $chance = chance_of_2dice_score($_, 6); print "Chances of rolling a $_ on two dice is: $chance\n"; } sub chance_of_2dice_score { my $score = shift; my $dice = shift; my %valid_dice = map {$_,1} (4,6,8,10,12,20); die "Invalid dice $dice" if (! $valid_dice{$dice}); my $count = 0; for my $first (1..$dice){ for my $second (1..$dice){ ++$count if (($first + $second) == $score); } } return ($count / ($dice * $dice)); }