From e9f43a54fc2653220a4da6272ce060775928fa67 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Fri, 25 Mar 2016 16:54:43 +0100 Subject: [PATCH] Tutorial files --- luhn.lhs | 13 +++++++++++++ test.lhs | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 luhn.lhs create mode 100644 test.lhs 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) +