Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # Chainmail joint probability of 6 LF vs 6 LF scoring (m,n) kills
- # using simultaneous turn sequence
- sub nFactorial { # Factorial n!
- my $n=shift;
- my $product = 1;
- while($n>0) {
- $product *= $n--;
- }
- $product;
- }
- sub nCr { # Combinations of n out of r
- my ($n,$r) = @_;
- int nFactorial($n) / int nFactorial($r) * int nFactorial($n-$r);
- }
- # Probability of 6 LF scoring n kills against 6 LF, n in 0..6
- sub prob {
- my ($n) = @_;
- nCr(6,$n) * (1/6)**$n * (5/6)**(6-$n);
- }
- for $c (0..6) { print " " x 10, $c; }; print "\n";
- for $dA (0..6) {
- print $dA, " ";
- for $dB (0..6) {
- my $p = prob($dA) * prob($dB);
- printf " %10.5g", $p;
- $check += $p;
- }
- print "\n";
- }
- print "Check: sum of probabilities = ", $check, "\n"; # Must be unity
Advertisement
Add Comment
Please, Sign In to add comment