Skip to content

Instantly share code, notes, and snippets.

@kmizu
Forked from tyano/Factorial.scala
Created August 26, 2010 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kmizu/551692 to your computer and use it in GitHub Desktop.
Save kmizu/551692 to your computer and use it in GitHub Desktop.
object Factorial {
def fact(n: Int) = (1 to n).foldLeft(1)(_*_)
def main(args: Array[String]) = {
val n = if(args.length == 0) 1 else args(0).toInt
1 to n foreach {i => println(i + "! = " + fact(i))}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment