Skip to content

Instantly share code, notes, and snippets.

@amuradyan
Created June 25, 2018 20:31
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 amuradyan/ae97d3d98abf5ea5c3bf41ece28833bb to your computer and use it in GitHub Desktop.
Save amuradyan/ae97d3d98abf5ea5c3bf41ece28833bb to your computer and use it in GitHub Desktop.
/**
* Created by spectrum on Jun, 2018
*/
object BigIntFactorial {
implicit def enhanceBigInt(n: BigInt) = new {
private val One = BigInt(1)
def ! = (One /: (One to n)) (_ * _)
}
val Zero = BigInt(0)
def factorial(n: BigInt): BigInt = n match {
case Zero => 1
case x: BigInt => x * factorial(x - 1)
}
def main(args: Array[String]): Unit = {
println(BigInt(4)!)
println(factorial(BigInt(10)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment