Skip to content

Instantly share code, notes, and snippets.

@raed667
Created October 11, 2014 22:18
Show Gist options
  • Save raed667/e74bdac850e87b2c1208 to your computer and use it in GitHub Desktop.
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
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