Created
January 15, 2017 19:01
-
-
Save JJ/a8634b671e78eda37dc513c6dec68294 to your computer and use it in GitHub Desktop.
Perl6 one liners, vol 3: Print n over m, or the binomial coefficient for n and m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The first argument will be n and entered into the $^ß placeholder, the second into the $^þ placeholder | |
perl6 -e 'say { ([*] 1..$^ß ) / ( [*] 1..$^þ) * ([*] 1..($^ß - $^þ)) }(@*ARGS[0],@*ARGS[1])' 20 11 | |
# [*] 1..$^ß ) will compute the factorial by creating a range 1..$^ß and then multiplying all of them together. | |
# @*ARGS contains the arguments handled to the script; @*ARGS[0] will be the first and so on. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment