Guest User

Untitled

a guest
May 23rd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 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. a, b, n := 0, 1, 0
  9. return func() int {
  10. a, b, n = b, a + b, n + 1
  11. return a
  12. }
  13. }
  14.  
  15. func main() {
  16. f := fibonacci()
  17. for i := 0; i < 10; i++ {
  18. fmt.Println(f())
  19. }
  20. }
Add Comment
Please, Sign In to add comment