' Methode iterative (performante)
Public Function Fact1(ByVal I As Integer) As UInt64
Fact1 = 1
For X = 2 To I : Fact1 *= X : Next
End Function
' Methode récursive (moins performante)
Public Function Fact2(ByVal I As Integer) As UInt64
If I < 1 Then Return 1
Return I * Fact2(I - 1)
End Function
' Methode à cache de données (hyper performante)
Public Function Fact3(ByVal I As Integer) As UInt64
Static Cache As UInt64() = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000, 20922789888000, 355687428096000, 6402373705728000, 121645100408832000, 2432902008176640000}
If I < 0 Then Return 1
If I < 21 Then Return Cache(I)
Fact3 = Cache(20)
For X As Integer = 21 To I
Fact3 *= X
Next
End Function