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