NPR
This algorithm finds all possible rearrangement of the element i.e all the possible permutation value.
private static long Factorial(int number)
{
if (number < 0)
return -1; //Error
long result = 1;
for (int i = 1; i <= number; ++i)
result *= i;
return result;
}
public static long NPR(int n, int r)
{
return Factorial(n) / Factorial(n - r);
}
Example
long npr = NPR(5, 2);
Output
20