Created
June 2, 2011 05:27
-
-
Save simeonwillbanks/1003980 to your computer and use it in GitHub Desktop.
#Ruby #math Calculate Permutations
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
# Permutations without Repetition | |
# | |
# n! | |
# -------- | |
# (n-r)! | |
def permutations(total) | |
(total-1).downto(1) do |i| | |
total = total * i unless i == 0 | |
end | |
total | |
end | |
puts permutations(16) # => 20922789888000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment