def factorial(x: BigInt): BigInt = { var result: BigInt = 1 var c = x; while (c > 1) { result *= c; c -= 1; } result }