From ab98b7cf3df361a5b340fe580f855dc78b7e01ae Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Thu, 22 Sep 2016 13:30:21 +0200 Subject: [PATCH] Restarting --- Homework 1/hanoi.hs | 13 ------------- Homework 1/luhn.lhs | 43 ------------------------------------------- README.md | 4 ++-- test.lhs | 13 ------------- 4 files changed, 2 insertions(+), 71 deletions(-) delete mode 100644 Homework 1/hanoi.hs delete mode 100644 Homework 1/luhn.lhs delete mode 100644 test.lhs diff --git a/Homework 1/hanoi.hs b/Homework 1/hanoi.hs deleted file mode 100644 index 17906dc..0000000 --- a/Homework 1/hanoi.hs +++ /dev/null @@ -1,13 +0,0 @@ - -type Peg = String -type Move = (Peg, Peg) - -hanoi :: Integer -> Peg -> Peg -> Peg -> [Move] -hanoi 1 a b c = [(a, c)] -hanoi n a b c = concat [ - hanoi (n-1) a c b, - hanoi 1 a b c, - hanoi (n-1) b a c ] - - - diff --git a/Homework 1/luhn.lhs b/Homework 1/luhn.lhs deleted file mode 100644 index fb5901d..0000000 --- a/Homework 1/luhn.lhs +++ /dev/null @@ -1,43 +0,0 @@ -This is an implementation of the Luhn Algorithm. It's used to validate -credit card numbers. - -Return the last digit of an integer number - -> lastDigit :: Integer -> Integer -> lastDigit n = mod n 10 - -Remove the last digit of an integer number and return the rest - -> dropLastDigit :: Integer -> Integer -> dropLastDigit n = div n 10 - -Put all digits of an integer number in reverse order into a list - -> toRevDigits :: Integer -> [Integer] -> toRevDigits n -> | n < 1 = [] -> | otherwise = lastDigit(n) : toRevDigits(dropLastDigit(n)) - -Put all digits of an integer number into a list - -> toDigits :: Integer -> [Integer] -> toDigits n = reverse(toRevDigits(n)) - -Double every second value in the input list. - -> doubleEveryOther :: [Integer] -> [Integer] -> doubleEveryOther([]) = [] -> doubleEveryOther(x:[]) = [x] -> doubleEveryOther(a:(b:xs)) = a : 2*b : doubleEveryOther(xs) - -Sum up all digits from all integers. - -> sumDigits :: [Integer] -> Integer -> sumDigits([]) = 0 -> sumDigits(0:xs) = sumDigits(xs) -> sumDigits(x:xs) = lastDigit(x) + sumDigits(dropLastDigit(x) : xs) - -Evaluate if a credit card number is 'valid'. - -> luhn :: Integer -> Bool -> luhn x = lastDigit(sumDigits(doubleEveryOther(toRevDigits(x)))) == 0 diff --git a/README.md b/README.md index 7e83378..a0a11de 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # CIS194 -CIS194 Haskell course +CIS194 Haskell course fall 2014 -http://www.seas.upenn.edu/~cis194/ +http://cis.upenn.edu/~cis194/fall14/ diff --git a/test.lhs b/test.lhs deleted file mode 100644 index 928cf31..0000000 --- a/test.lhs +++ /dev/null @@ -1,13 +0,0 @@ - -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) -