Skip to content

Instantly share code, notes, and snippets.

@JJ
Created January 15, 2017 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JJ/a8634b671e78eda37dc513c6dec68294 to your computer and use it in GitHub Desktop.
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
# 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