官术网_书友最值得收藏!

How to do it...

  1. Declare a function called fibonacci() and use the generateSequence() function to define a formula for the next elements of the sequence:
fun fibonacci(): Sequence<Int> {
return generateSequence(Pair(0, 1)) { Pair(it.second, it.first + it.second) }
.map { it.first }
}
  1. Use the fibonacci() function to print the next Fibonacci numbers to the console:
println(fibonacci().take(20).toList())

主站蜘蛛池模板: 宜宾县| 肇庆市| 定兴县| 辽阳市| 雅安市| 怀安县| 乐陵市| 邢台县| 丹江口市| 油尖旺区| 芜湖市| 江西省| 铜梁县| 德令哈市| 历史| 普宁市| 施甸县| 南宫市| 隆尧县| 镇江市| 南宁市| 班戈县| 句容市| 阿拉善右旗| 钦州市| 从江县| 商洛市| 丹棱县| 佛冈县| 小金县| 云龙县| 河东区| 夏河县| 鄯善县| 桓仁| 靖边县| 南部县| 嵊州市| 仲巴县| 遂川县| 晋城|