Skip to content

Instantly share code, notes, and snippets.

@a-suenami
Created March 27, 2013 04:02
Show Gist options
  • Save a-suenami/5251539 to your computer and use it in GitHub Desktop.
Save a-suenami/5251539 to your computer and use it in GitHub Desktop.
scalaでフィボナッチ数列。
object Fib extends App {
def fib(n: Int): Int = {
if (n < 2) { return n } else { return fib(n-1) + fib(n-2) }
}
Console.println("fib(1) = " + fib(1));
Console.println("fib(2) = " + fib(2));
Console.println("fib(3) = " + fib(3));
Console.println("fib(4) = " + fib(4));
Console.println("fib(5) = " + fib(5));
Console.println("fib(6) = " + fib(6));
Console.println("fib(7) = " + fib(7));
Console.println("fib(8) = " + fib(8));
Console.println("fib(9) = " + fib(9));
Console.println("fib(10) = " + fib(10));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment