Skip to content

Instantly share code, notes, and snippets.

@abevoelker
Created June 27, 2011 06:11
Show Gist options
  • Save abevoelker/1048381 to your computer and use it in GitHub Desktop.
Save abevoelker/1048381 to your computer and use it in GitHub Desktop.
Factorial in Scala
// Test directly from shell using (e.g. input 5):
// scala -i factorial.scala -e 'println(factorial(5))'
def factorial(n: BigInt): BigInt = {
if (n <= 1)
1
else
n * factorial(n - 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment