pythonがこの先生きの ..
[2ch|▼Menu]
150:デフォルトの名無しさん
07/12/01 18:51:41 .net
Pythonオワタ・・・orz
俺もう乗り換えるわ

Running the snippets above, I got the following results:

Python 2.5.1:   31.507s
Ruby 1.9.0:    11.934s

The Ruby code:

def fib(n)
 if n == 0 || n == 1
  n
 else
  fib(n-1) + fib(n-2)
 end
end

36.times do |i|
 puts "n=#{i} => #{fib(i)}"
end

And the Python equivalent:

def fib(n):
  if n == 0 or n == 1:
   return n
  else:
   return fib(n-1) + fib(n-2)

for i in range(36):
  print "n=%d => %d" % (i, fib(i))


次ページ
続きを表示
1を表示
最新レス表示
スレッドの検索
類似スレ一覧
話題のニュース
おまかせリスト
▼オプションを表示
暇つぶし2ch

3221日前に更新/149 KB
担当:undef