Skip to content

Instantly share code, notes, and snippets.

@simeonwillbanks
Created June 2, 2011 05:27
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 simeonwillbanks/1003980 to your computer and use it in GitHub Desktop.
Save simeonwillbanks/1003980 to your computer and use it in GitHub Desktop.
#Ruby #math Calculate Permutations
# 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