Tutorial files
This commit is contained in:
commit
e9f43a54fc
2 changed files with 26 additions and 0 deletions
13
luhn.lhs
Normal file
13
luhn.lhs
Normal 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
13
test.lhs
Normal 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)
|
||||||
|
|
Loading…
Reference in a new issue