Created
December 2, 2011 01:16
-
-
Save moderation/1421189 to your computer and use it in GitHub Desktop.
will it recur fibonacci
This file contains hidden or 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" | |
"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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using weekly.2011-12-02 - https://groups.google.com/forum/#!topic/golang-nuts/gCzldiP_-2c