Enjoy Life

A Ryan Gene Blog!

Tuesday, July 25, 2006

[Code]用Ruby写Fibonacci函数

Ruby是门好语言,使得编程变得非常优雅

下面一个例子很好体现了这点:

很简单地实现了Fibonacci函数


def fib_up_to(max)
i1, i2 = 1, 1
while i1 <= max
yield i1
i1, i2 = i2, i1+i2
end
end

fib_up_to(1000) {|f| print f, " " }


输出:
1 1 2 3 5 8 13 21 34 55 89 ...

posted by Ryan Gene at 9:53 PM

6 Comments:

Anonymous Anonymous said...

我是bloger杀手

7/26/2006 10:52 AM  
Anonymous Anonymous said...

看不懂~~

7/26/2006 8:53 PM  
Anonymous Anonymous said...

To be honest, I still prefer python.

7/27/2006 7:44 PM  
Blogger Ryan Gene said...

想了一想,我还是专心搞Hibernate

8/01/2006 9:32 AM  
Anonymous Anonymous said...

我不懂Python也不懂Ruby,有空可以稍稍看点。

对于Hibernate我觉得很好,但是同时使用的技术含量较大,应该多花时间学习才会有所收获。

8/01/2006 12:50 PM  
Blogger Ryan Gene said...

对,所以现在静心学习:>

8/01/2006 12:56 PM  

Post a Comment

<< Home

Name:
Location: Shanghai, Shanghai, China

Powered by Blogger
Powered by Writely

Add to Google

Site Feed