Guest User

Untitled

a guest
Sep 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. // fibonacci is a function that returns
  6. // a function that returns an int.
  7. func fibonacci() func() int {
  8. a1 := 0
  9. a2 := 1
  10. return func() int {
  11. t := a2
  12. a2 = a1 + a2
  13. a1 = t
  14. return a2
  15. }
  16. }
  17.  
  18. func main() {
  19. f := fibonacci()
  20. for i := 0; i < 10; i++ {
  21. fmt.Println(f())
  22. }
  23. }
Add Comment
Please, Sign In to add comment