Skip to content

Instantly share code, notes, and snippets.

@bigjason
Created February 29, 2016 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigjason/e7b0698e1731a27a0a5e to your computer and use it in GitHub Desktop.
Save bigjason/e7b0698e1731a27a0a5e to your computer and use it in GitHub Desktop.
@scala.annotation.tailrec
def fact(n: Int, acc: BigInt = 1): BigInt =
if(n < 0) throw new Exception("n must be >= 0")
else if (n == 0) acc
else fact(n - 1, acc * n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment