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 ...

相关文章:

  • 2022-03-05
  • 2021-07-14
  • 2021-11-27
  • 2021-06-08
  • 2021-10-13
  • 2021-12-13
  • 2021-10-02
  • 2022-12-23
猜你喜欢
  • 2021-11-28
  • 2021-09-17
  • 2022-03-02
  • 2021-06-25
  • 2022-02-07
相关资源
相似解决方案