Binomial Coefficient

AUTHOR

L. Grondin

Number of ways to choose P objects among N. It's also the coefficient of the monome of degree P in the expansion of (1 + X)^N, thus the name.

N       (N-P+1)*(N-P+2)*...*N
   (   ) = āˆ‘ -------------------
     P         1*2*...*P

More

http://rosettacode.org/wiki/Evaluate_binomial_coefficients#Raku

Notable features used

  • infix sub definition

  • reduction meta-operator

  • self-declared parameters

  • sequence operator to get a decreasing order

  • Zip metaoperator with list of different sizes

  • use of rational numbers as a default

use v6;



sub infix:<choose> { [*] ($^n ... 0) Z/ 1 .. $^p }

say 5 choose 3;

# vim: expandtab shiftwidth=4 ft=perl6

See Also

100-doors.pl

100 Doors

24-game.pl

24 game

accumulator-factory.pl

Accumulator factory

ackermann-function.pl

Ackermann function

arbitrary-precision-integers.pl

Arbitrary-precision integers (included)

balanced-brackets.pl

Balanced brackets

copy-a-string.pl

Copy a string

create-a-two-dimensional-array-at-runtime.pl

Create a two-dimensional array at runtime

hailstone-sequence.pl

Hailstone sequence

last-fridays-of-year.pl

Last fridays of the year

prime-decomposition.pl

Prime decomposition

README.md

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.