Advertisement
Guest User

Untitled

a guest
Jun 1st, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 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. current := 0
  9. next := 1
  10. return func() int {
  11. result := current
  12. current = next
  13. next = result + next
  14. return result
  15. }
  16. }
  17.  
  18. func main() {
  19. f := fibonacci()
  20. for i := 0; i < 10; i++ {
  21. fmt.Println(f())
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement