in reply to Odds between two players flipping a coin M and N times

Here is some simpler code that computes the probability that player A tossing a coin $m times gets a greater number of heads than player B tossing a coin $n times, for probability of heads on each toss $p.
#!/usr/bin/perl -w use strict; my ($m, $n, $p) = @ARGV; my $prob = 0; foreach my $x (1..$m) { foreach my $y (0..$x-1) { $prob += choose($m, $x) * choose($n, $y) * $p**($x + $y) * (1-$p)**($m + $n - $x - $y); } } print "$prob\n"; sub choose { my ($n, $k) = @_; my $choose = 1; foreach my $i (0..$k-1) { $choose *= ($n-$i)/($i+1); } return $choose; }
-Mark