Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,6 @@
def factorial(n: Int) = {
var res = 1
for (i <- 1 to n)
res *= i
res
}

View file

@ -0,0 +1,3 @@
def factorial(n: Int): Int =
if (n < 1) 1
else n * factorial(n - 1)

View file

@ -0,0 +1,6 @@
def factorial(n: Int) = {
@tailrec def fact(x: Int, acc: Int): Int = {
if (x < 2) acc else fact(x - 1, acc * x)
}
fact(n, 1)
}

View file

@ -0,0 +1 @@
def factorial(n: Int) = (2 to n).product

View file

@ -0,0 +1,2 @@
def factorial(n: Int) =
(2 to n).foldLeft(1)(_ * _)

View file

@ -0,0 +1,3 @@
implicit def IntToFac(i : Int) = new {
def ! = (2 to i).foldLeft(BigInt(1))(_ * _)
}