[导入][Code]用Ruby写Fibonacci函数

Ruby是门好语言,使得编程变得非常优雅下面一个例子很好体现了这点: 很简单地实现了Fibonacci函数
def fib_up_to(max)  i1, i2 = 1, 1   while i1 <= max    yield i1    i1, i2 = i2, i1+i2  endendfib_up_to(1000) {|f| print f, " " }
输出:1 1 2 3 5 8 13 21 34 55 89 ...
原文地址:https://www.cnblogs.com/jinweijie/p/567792.html