comparison Looping.rb @ 5:861b93741d60

id:sumim氏のSmalltalk版とRuby版のコードを追加。
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Thu, 17 Feb 2011 11:32:17 +0900
parents
children 30da8c1da4d4
comparison
equal deleted inserted replaced
3:57283e4fdd4b 5:861b93741d60
1 #!/usr/bin/env ruby
2 class Looping
3 def initialize
4 @n0 = 0
5 end
6
7 def calc(n)
8 n1 = @n0 + (1 - 2*(n%2))
9 @n0 = n
10 return n1
11 end
12 end
13
14 l = Looping.new
15 n = 1
16 t1 = Time.now
17 2147483647.times{ |c|
18 n = l.calc(n)
19 }
20 t2 = Time.now
21 print "#{n}\nRuby\t#{t2 - t1}\n"
22