Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private tmr As CTiming
- Private Sub Main()
- Set tmr = New CTiming
- Dim x As Long
- Dim MENSAJE As String
- MENSAJE = "**PRUEBA CON NUMEROS POSITIVOS HASTA EL MAX**" & vbNewLine
- tmr.Reset
- For x = 0 To 46340
- Call IsFibonacci7913(x)
- Next
- MENSAJE = MENSAJE & "7913: " & tmr.sElapsed & vbNewLine
- tmr.Reset
- For x = 0 To 46340
- Call isFibbonacci(x)
- Next
- MENSAJE = MENSAJE & "BZro: " & tmr.sElapsed & vbNewLine
- tmr.Reset
- For x = 0 To 46340
- Call IsFibonacci(x)
- Next
- MENSAJE = MENSAJE & "E__C: " & tmr.sElapsed & vbNewLine
- tmr.Reset
- For x = 0 To 46340
- Call IsFibonacciMrFrog(x)
- Next
- MENSAJE = MENSAJE & "Frog: " & tmr.sElapsed & vbNewLine
- tmr.Reset
- For x = 0 To 46340
- Call isFibbonacciNum(x)
- Next
- MENSAJE = MENSAJE & "Dark: " & tmr.sElapsed & vbNewLine
- Open App.Path & "Output.txt" For Output As #1
- Write #1, "******TEST HECHO POR 79137913******"
- Close #1
- Open App.Path & "Output.txt" For Append As #1
- Print #1, MENSAJE
- Close #1
- Shell "notepad.exe " & App.Path & "Output.txt", vbMaximizedFocus
- End
- End Sub
- Public Function IsFibonacci(ByRef lNumber As Long) As Boolean
- Dim i As Long 'anterior
- Dim y As Long 'actual
- Dim x As Long 'Restultado a checkear
- i = 1
- y = 1
- Do While x < lNumber
- x = i + y
- i = y
- y = x
- If x = lNumber Then IsFibonacci = True: Exit Function
- Loop
- IsFibonacci = False
- End Function
- Function isFibbonacciNum(ByVal lNumber As Long) As Boolean
- Dim Fn0 As Double
- Dim Fn1 As Double
- Dim i As Double
- Dim Num As Double
- Fn0 = 0
- Fn1 = 1
- isFibbonacciNum = False
- If lNumber = 0 Or lNumber = 1 Then isFibbonacciNum = True: Exit Function
- For i = 1 To lNumber
- Num = Fn0 + Fn1
- Fn0 = Fn1
- Fn1 = Num
- If Num = lNumber Then isFibbonacciNum = True: Exit Function
- If Num > lNumber Then Exit Function
- Next
- End Function
- Public Static Function IsFibonacciMrFrog(ByVal lngNumber As Long) As Boolean
- Dim dblRaised As Double
- Dim dblSum As Double
- Dim dblSqr As Double
- dblRaised = lngNumber * lngNumber
- dblSum = dblRaised + dblRaised + dblRaised + dblRaised + dblRaised + &H4
- dblSqr = Sqr(dblSum)
- IsFibonacciMrFrog = (dblSqr - Int(dblSqr) = &H0)
- If IsFibonacciMrFrog Then Exit Function
- dblSum = dblSum - &H8
- dblSqr = Sqr(dblSum)
- IsFibonacciMrFrog = (dblSqr - Int(dblSqr) = &H0)
- End Function
- Function isFibbonacci(ByVal vVal&) As Boolean
- Dim dbl_v#(0 To 1)
- Dim byt_i As Byte
- dbl_v#(1) = 1
- dbl_v#(0) = 0
- Do Until dbl_v#(byt_i) >= vVal&
- dbl_v#(byt_i) = dbl_v#(byt_i) + dbl_v#(byt_i Xor 1)
- byt_i = byt_i Xor 1
- Loop
- If dbl_v#(0) = vVal& Or dbl_v#(1) = vVal& Then
- isFibbonacci = True
- End If
- End Function
- Private Function IsFibonacci7913(ByVal N As Long) As Boolean
- ' If N < &H0 Then
- ' If N = -1 Then IsFibonacci7913 = True: Exit Function
- ' Dim Neg0 As Double
- ' Dim Neg1 As Double
- ' Dim Neg2 As Double
- ' Neg0 = &H0
- ' Neg1 = &H1
- ' Do While Not (Neg1 < N)
- ' Neg2 = Neg0
- ' Neg0 = Neg1
- ' Neg1 = (Neg2 - Neg0)
- ' Loop
- ' If N = Neg2 Then IsFibonacci7913 = True
- ' Exit Function
- ' End If
- If N = &H0 Then IsFibonacci7913 = True: Exit Function
- Dim Aux0 As Double
- Dim Aux1 As Double
- Dim Aux2 As Double
- Aux2 = N * N
- Aux2 = Aux2 + Aux2 + Aux2 + Aux2 + Aux2
- Aux1 = Aux2 + &H4
- Aux1 = Sqr(Aux1)
- If Aux1 - (CLng(Aux1)) = &H0 Then IsFibonacci7913 = True: Exit Function
- Aux0 = Aux2 - &H4
- Aux0 = Sqr(Aux0)
- If Aux0 - (CLng(Aux0)) = &H0 Then IsFibonacci7913 = True
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement