LoginSignup
2
2

More than 5 years have passed since last update.

Scalaの並列コレクションでフィボナッチ数列

Last updated at Posted at 2016-02-14

フィボナッチ数列を計算

Fib.scala
object Fib {
  def main(args: Array[String]): Unit = {
    println ((1 to 30).par.map(x => fib(x)))
  }
  def fib(n: Int): Int = if(n < 2) 1 else fib(n - 1) + fib(n - 2)
}

出力:
ParVector(1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269)

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2