Method: Numeric#perms

Defined in:
lib/epitools/core_ext/numbers.rb

#perms(r) ⇒ Object Also known as: permutations

Permutations: compute “n P r”

This represents number of ways to pick “r” items from a collection of “self” items (where the order of the items DOES matter, and items can’t be repeated.)

eg: 23.perm(3) is how many ways 23 people can win 1st, 2nd and 3rd place in a race.

Formula: n! / (n - r)!



151
152
153
# File 'lib/epitools/core_ext/numbers.rb', line 151

def perms(r)
  (self-r+1..self).reduce(:*)
end