Created
October 11, 2014 22:18
-
-
Save raed667/e74bdac850e87b2c1208 to your computer and use it in GitHub Desktop.
This is a test in Go for Fibonacci in an iterative way. The algorithm disolays the entire suite to provided 'n' and the time it took to compute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
import ( | |
"time" | |
"log" | |
) | |
func main() { | |
fibonacci(1000) | |
} | |
func fibonacci(n int) { | |
start := time.Now() | |
u:=0 | |
v:=1 | |
var ( | |
t int | |
) | |
for i:=2; i <= n ;i++ { | |
t = u + v | |
u = v | |
v = t | |
fmt.Println(v) | |
} | |
elapsed := time.Since(start) | |
log.Printf("Fibonacci of %v took %s",n, elapsed) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment