Created
February 15, 2018 17:05
-
-
Save c-yan/e10eaa07aae68a41aafc763f7d501792 to your computer and use it in GitHub Desktop.
Fibonacci number
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" | |
"github.com/BenLubar/memoize" | |
) | |
func main() { | |
var fib func(uint64) uint64 | |
fib = func(n uint64) uint64 { | |
switch { | |
case n == 0: | |
return 0 | |
case n == 1: | |
return 1 | |
default: | |
return fib(n-1) + fib(n-2) | |
} | |
} | |
fib = memoize.Memoize(fib).(func(uint64) uint64) | |
fmt.Println(fib(100)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment