annotate Looping.rb @ 7:69b8c75e9c24 default

Scalaのソースコードを追加。
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Fri, 18 Feb 2011 10:32:06 +0900
parents 861b93741d60
children 30da8c1da4d4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
1 #!/usr/bin/env ruby
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
2 class Looping
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
3 def initialize
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
4 @n0 = 0
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
5 end
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
6
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
7 def calc(n)
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
8 n1 = @n0 + (1 - 2*(n%2))
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
9 @n0 = n
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
10 return n1
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
11 end
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
12 end
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
13
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
14 l = Looping.new
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
15 n = 1
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
16 t1 = Time.now
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
17 2147483647.times{ |c|
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
18 n = l.calc(n)
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
19 }
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
20 t2 = Time.now
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
21 print "#{n}\nRuby\t#{t2 - t1}\n"
861b93741d60 id:sumim氏のSmalltalk版とRuby版のコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
22