commit e9f43a54fc2653220a4da6272ce060775928fa67 Author: Michael Mandl Date: Fri Mar 25 16:54:43 2016 +0100 Tutorial files diff --git a/luhn.lhs b/luhn.lhs new file mode 100644 index 0000000..6096209 --- /dev/null +++ b/luhn.lhs @@ -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)) + diff --git a/test.lhs b/test.lhs new file mode 100644 index 0000000..928cf31 --- /dev/null +++ b/test.lhs @@ -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) +