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, b := 1, 0
- return func() int {
- c := b
- b = a + b
- a = 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