in reply to Re: New Jersey Lottery Probability
in thread New Jersey Lottery Probability
Another approach that requires thinking a bit backwards:sub permutation { my ($prob, $start) = (1, shift); $prob *= $start-- foreach (1 .. $_[0]); $prob; }
Even shorter and harder on the eyes:sub permutation { my $prob = 1; $prob *= $_ foreach ((($_[0]+1) - $_[1]) .. $_[0]); return $prob; }
I stand by the first I posted, though. Anyone who can get this down to a single statement gets my respect.sub permutation { my $prob = 1; return (map { $prob *= $_ } (($_[0] - $_[1] + 1) .. $_[0]))[-1]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: Re: New Jersey Lottery Probability
by perlmonkey (Hermit) on May 04, 2000 at 11:34 UTC | |
|
RE: RE: Re: New Jersey Lottery Probability
by perlmonkey (Hermit) on May 04, 2000 at 05:55 UTC |