Skip to content

Instantly share code, notes, and snippets.

@moderation
Created December 2, 2011 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moderation/1421189 to your computer and use it in GitHub Desktop.
Save moderation/1421189 to your computer and use it in GitHub Desktop.
will it recur fibonacci
package main
import (
"fmt"
"time"
)
func fibonacci(n int) int {
var a int
if n < 2 {
a = 1
} else {
a = fibonacci(n - 2) + fibonacci(n - 1)
}
return a
}
func main() {
time1 := time.Now()
fmt.Println(fibonacci(40))
time2 := time.Now()
elapsed := float32(time2.Sub(time1)) / 1e6
fmt.Printf("Elapsed time: %.4f milliseconds\n", elapsed)
}
@moderation
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment