def factorial(x: BigInt) = { def factorialHelper(x: BigInt, total: BigInt): BigInt = { if (x < 2) total else factorialHelper(x-1, total*x) } factorialHelper(x,1) }