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 @@
factorial n = product [1..n]

View file

@ -0,0 +1 @@
factorial = product . enumFromTo 1

View file

@ -0,0 +1 @@
factorial n = foldl (*) 1 [1..n]

View file

@ -0,0 +1 @@
factorials = scanl (*) 1 [1..]

View file

@ -0,0 +1,3 @@
factorial :: Integral -> Integral
factorial 0 = 1
factorial n = n * factorial (n-1)

View file

@ -0,0 +1,5 @@
fac n
| n >= 0 = go 1 n
| otherwise = error "Negative factorial!"
where go acc 0 = acc
go acc n = go (acc * n) (n - 1)

View file

@ -0,0 +1,10 @@
{-# LANGUAGE PostfixOperators #-}
(!) :: Integer -> Integer
(!) 0 = 1
(!) n = n * (pred n !)
main :: IO ()
main = do
print (5 !)
print ((4 !) !)

View file

@ -0,0 +1,8 @@
-- product of [a,a+1..b]
productFromTo a b =
if a>b then 1
else if a == b then a
else productFromTo a c * productFromTo (c+1) b
where c = (a+b) `div` 2
factorial = productFromTo 1