Skip to content

Commit f19628b

Browse files
author
L. Grondin
committed
adding binomial coefficient example
1 parent 8a4d87f commit f19628b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
=begin pod
2+
3+
=head1 Binomial Coefficient
4+
5+
Number of ways to choose P objects among N. It's also the coefficient of the
6+
monome of degree P in the expansion of (1 + X)^N, thus the name.
7+
8+
9+
N (N-P+1)*(N-P)*...*N
10+
( ) = ∑ -------------------
11+
P 1*2*...*P
12+
13+
14+
=head1 More
15+
16+
L<http://rosettacode.org/wiki/Evaluate_binomial_coefficients#Perl_6>
17+
18+
=head1 Notable features used
19+
20+
=item infix sub definition
21+
=item reduction meta-operator
22+
=item self-declared parameters
23+
=item range operator with first value excluded
24+
=item Zip metaoperator with an infinite liste on the right side
25+
=item use of rational numbers as a default
26+
27+
=end pod
28+
29+
sub infix:<choose> { [*] $^n - $^p ^.. $n Z/ 1 .. * }
30+
31+
say 5 choose 3;

0 commit comments

Comments
 (0)