Tutorial files

This commit is contained in:
Michael Mandl 2016-03-25 16:54:43 +01:00
commit e9f43a54fc
2 changed files with 26 additions and 0 deletions

13
luhn.lhs Normal file
View file

@ -0,0 +1,13 @@
This is an implementation of the Luhn Algorithm. It's used to validate credit card numbers.
> lastDigit :: Integer -> Integer
> lastDigit n = mod n 10
> dropLastDigit :: Integer -> Integer
> dropLastDigit n = div n 10
> toRevDigits :: Integer -> [Integer]
> toRevDigits n
> | n < 1 = []
> | otherwise = lastDigit(n) : toRevDigits(dropLastDigit(n))

13
test.lhs Normal file
View file

@ -0,0 +1,13 @@
Compute the factorial of a given integer number n.
> fac :: Integer -> Integer
> fac 0 = 1
> fac n = n * fac(n-1)
Compute the sum of of all integer numbers from 1 to n.
> sumTo :: Integer -> Integer
> sumTo 0 = 0
> sumTo n = n + sumTo(n-1)