mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-25 14:26:04 +03:00
Added fibonacci example
This commit is contained in:
parent
6240073da1
commit
135ae1e4e1
18
functional_programming/ch01/fibonacci.go
Normal file
18
functional_programming/ch01/fibonacci.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func Fibonacci(x int) int {
|
||||||
|
if x == 0 {
|
||||||
|
return 0
|
||||||
|
} else if x <= 2 {
|
||||||
|
return 1
|
||||||
|
} else {
|
||||||
|
return Fibonacci(x-2) + Fibonacci(x-1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fib := Fibonacci
|
||||||
|
fmt.Printf("%vn", fib(50))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user