/*
What is a permutation?
A permutation is a selection of items from a list where the order does not matter. This means, the selected pairs can include duplicate items in differing orders (i.e., [AB] and [BA]). (In fact, combination locks for doors, lockers, and bike chains might be better named “permutation locks”, since they allow for differing orders of the same digits in a password!)
For example, if you have a list of items [A, B, C, D, E], the permutations from this list will include [AB], [BA], [AC], [CA], [AD], [DA], [AE], [EA], [BC], [CB], [BD], [DB], [BE], [EB], [CD], [DC], [CE], [EC], [DE], [ED].
To calculate the number of permutations that can be formed from selecting r elements from a list of n total elements, we can use the following formula, as follows:
N Permute K
n is the number of total elements in the list.
k is the number of elements within each pair.
n! / (n- k)!
5P2 = 5! / (5 - 2)! = 20
[A, B, C, D, E]
[AB], [BA], [AC], [CA], [AD], [DA], [AE], [EA], [BC], [CB], [BD], [DB], [BE], [EB], [CD], [DC], [CE], [EC], [DE], [ED]
5P3 = 5! / (5 - 3)! = 60
*/
using System;
public class Program
{
public static void Main()
Console.WriteLine(NumberOfPermutations(5, 3));
}
static int NumberOfPermutations(int n, int k)
int result = 0;
int denominator = Factorial(n-k);
if(denominator > 0)
result = Factorial(n) / denominator;
return result;
static int Factorial(int n)
int result = 1;
for (int i = n; i > 0; i--)
result = result * i;