A Tour of Go---Exercise: Fibonacci closure
来源:互联网 发布:php开源oa办公系统 编辑:程序博客网 时间:2024/05/17 00:16
练习:斐波纳契闭包
https://tour.golang.org/moretypes/26
Implement a fibonacci
function that returns a function (a closure) that returns successive fibonacci numbers (0, 1, 1, 2, 3, 5, ...).
实现一个 fibonacci
函数,返回一个函数(一个闭包)可以返回连续的斐波纳契数。
package mainimport "fmt"// fibonacci 函数会返回一个返回 int 的函数。func fibonacci() func() int {pre := -1sum := 1return func() int {pre, sum = sum, pre+sumreturn sum}}func main() {f := fibonacci()for i := 0; i < 10; i++ {fmt.Println(f())}}
0 0
- A Tour of Go---Exercise: Fibonacci closure
- A Tour of Go: Exercise: Rot13 Reader
- go语言Exercise: Fibonacci closure
- 【GoLang笔记】A Tour of Go - Exercise: Equivalent Binary Trees
- 【GoLang笔记】A Tour of Go - Exercise: Images
- 【GoLang笔记】A Tour of Go - Exercise: Web Crawler
- A Tour of Go Named results
- A tour of Go的疑问
- golang官方指导练习(go tour exercise)
- Scala call-by-name evalutation (A Tour of Scala: Automatic Type-Dependent Closure Construction)
- 【Go语言(golang)教程】A Tour of Go 七十集大全
- A Tour of C++
- A Tour of Golang (二)
- go closure
- A simple example of PHP closure
- Introduction A Guided Tour of the POCO
- a quick tour of many tools
- A Tour of Machine Learning Algorithms
- 二叉树基本概念及性质
- hdu5510(并查集+KMP)
- linux(centos 7)下编译 hello World
- 循环
- hadoop VMware伪分布式
- A Tour of Go---Exercise: Fibonacci closure
- 二叉树编程实践
- 顶级开源人工智能工具推荐
- Java微信开发入门
- Ubuntu 16.04配置Java开发环境
- C编译过程总结
- 地理数据格式转换(geojson、kml等)
- 【机器学习】深入理解拉格朗日乘子法(Lagrange Multiplier) 和KKT条件
- [LeetCode 144] Binary Tree Preorder Traversal(迭代法)