NPR

This algorithm finds all possible rearrangement of the element i.e all the possible permutation value.



									Private Shared Function Factorial(number As Integer) As Long
	If number < 0 Then
		Return -1 'Error
	End If

	Dim result As Long = 1

	For i As Integer = 1 To number
		result *= i
	Next

	Return result
End Function

Public Shared Function NPR(n As Integer, r As Integer) As Long
	Return Factorial(n) \ Factorial(n - r)
End Function
								


Example

									Dim _NPR = NPR(5, 2)
								


Output

									20