annotate Looping.scala @ 12:dab1e83799e4 >>178 tip

R版のソースコードを追加。
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Sat, 04 Feb 2012 04:10:01 +0900
parents 69b8c75e9c24
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
1 class LClass {
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
2 def calc(n:Int): Int = {
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
3 var n1 = n0 + (1 - 2*(n%2))
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
4 n0 = n;
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
5 return n1;
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
6 }
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
7 private var n0:Int = 0
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
8 }
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
9
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
10 object Looping {
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
11 def main(args :Array[String]):Unit = {
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
12 var o = new LClass()
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
13 var n = 1
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
14 var t1 = System.currentTimeMillis()
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
15 for(c <- 0 to Integer.MAX_VALUE - 1){
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
16 n = o.calc(n);
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
17 }
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
18 var t2 = System.currentTimeMillis()
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
19 println(n + "\nScala:\t" + (t2 - t1))
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
20 }
69b8c75e9c24 Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
21 }