44999623da
since I was in here looking at something unrelated...
24 lines
330 B
Go
24 lines
330 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
// fibonacci is a function that returns
|
|
// a function that returns an int.
|
|
func fibonacci() func() int {
|
|
prev := 0
|
|
cur := 1
|
|
return func() int {
|
|
old_cur := cur
|
|
cur = prev + cur
|
|
prev = old_cur
|
|
return cur
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
f := fibonacci()
|
|
for i := 0; i < 10; i++ {
|
|
fmt.Println(f())
|
|
}
|
|
}
|