package main

import (
    "fmt"
)

func main() {
    f := fibonacci()
    for i := 0; i < 10; i++ {
        fmt.Printf("%d:%d\n", i, f())
    }
}

// func fibonaci(n int) (ret int) {
//     if n <= 1 {
//         ret = 1
//     } else {
//         ret = fibonaci(n-1) + fibonaci(n-2)
//     }
//     return ret
// }

func fibonacci() func() int {
    f0, f1, f2 := 1, 1, 0
    index := -1
    return func() int {
        index++
        if index == 0 {
            return 1
        } else if index == 1 {
            return 1
        } else {
            f2 = f0 + f1
            f0 = f1
            f1 = f2
            return f2
        }
    }
}

最新文章

  1. Maven 整合FreeMarker使用
  2. 让你的JS更优雅的小技巧
  3. Ubuntu 汉化时ubuntu software database is broken错误解决
  4. 开发中model,entity和pojo的区别
  5. iOS开发之网络编程--5、NSURLSessionUploadTask+NSURLSessionDataDelegate代理上传
  6. ERROR com.opensymphony.xwork2.interceptor.ParametersInterceptor.error:34 - Developer Notification
  7. winform中嵌入Ppt、Word、Excel
  8. Lucene/ElasticSearch 学习系列 (2) Information Retrival 初步之名词解释
  9. IOS离线教程下载与Dash的使用
  10. hdu 2147 kiki&#39;s game 博弈论
  11. MySQL开启远程链接(2014.12.12)
  12. 能发送http请求(get,post)的工具
  13. c# 服务程序重启自身
  14. JS的一些常见验证代码
  15. A Simple Math Problem(矩阵快速幂)(寒假闭关第一题,有点曲折啊)
  16. Error Code: 1068. Multiple primary key defined
  17. thinkphp框架的大D方法应用
  18. Docker打包 Asp.Net Core应用,在CentOS上运行(转)
  19. ifconfig和ping
  20. ACM-ICPC 2018 沈阳赛区网络预赛 K题

热门文章

  1. hint: not have locally. This is usually caused by another repository pushing
  2. 北京Python开发培训怎么选?
  3. 关于static关键字的思考
  4. Attention-based Model
  5. cogs——49. 跳马问题
  6. python爬虫20 | 小帅b教你如何使用python识别图片验证码
  7. 手机浏览PC版页面出现背景图片显示不全的问题解决方案
  8. (45). Spring Boot MyBatis连接Mysql数据库【从零开始学Spring Boot】
  9. ACDream - Xor pairs
  10. CODEVS——T 1049 棋盘染色