Guest User

Untitled

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