You are of course correct it's calculating permutations not combinations, the following sorts that out. No I'm not going to do all obfuscation stuff on it :-0
#!/usr/bin/perl -w
use strict;
my ($number, $times) = (50, 5);
print &permutation($number, $times) * 36 / ($times + 1);
sub permutation {
my ($prob, $number, $times) = (1, @_);
while($times) {
$prob *= ($number - $times + 1) / $times--;
};
$prob;
};
|