Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- // fibonacci is a function that returns
- // a function that returns an int.
- func fibonacci() func() int {
- a := 1
- b := 1
- c := 0
- n := 0
- return func() int {
- n += 1
- if n < 3 {return 1}
- c = a + b
- a, b = b, c
- return b
- }
- }
- func main() {
- f := fibonacci()
- for i := 0; i < 10; i++ {
- fmt.Println(f())
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement