module Exercise01 where import Test.QuickCheck {-H1.1a)-} myPair :: Integer -> Integer -> Integer myPair x y = (2 ^ y) * (2 * x + 1) -1 {-H1.1b)-} mySnd :: Integer -> Integer mySnd y | odd (y `mod` 2) = 1 + mySnd ((y - 1) `div` 2) | otherwise = 0 {-H1.1c)-} myFst :: Integer -> Integer myFst x | odd x = myFst (x `div` 2) | otherwise = x `div` 2 {-H1.1d)-} prop_myPair :: Integer -> Integer -> Integer -> Property prop_myPair p x y = (x >= 0) && (y >= 0) && (p >= 0) ==> myPair x y == p {-H2-} digitToEo :: Integer -> String digitToEo 0 = "nul" digitToEo 1 = "unu" digitToEo 2 = "du" digitToEo 3 = "tri" digitToEo 4 = "kvar" digitToEo 5 = "kvin" digitToEo 6 = "ses" digitToEo 7 = "sep" digitToEo 8 = "ok" digitToEo 9 = "nau" {-WETT-} {- Eingabe wird evaluiert -} numberToEo :: Integer -> String numberToEo n | n < 10 = digitToEo n | n < 100 = calc n 10 "dek" | n < 1000 = calc n 100 "cent" | n < 1000000 = unwords(words(calc n 1000 " mil")) | otherwise = calcMil n $calcPot n 6 {- Zahlen unter 10^6 erhalten kein unu vor dek/cent/mil Aufteilung is Zahl + Rest -} calc :: Integer -> Integer -> String -> String calc n x s = (if y /= 1 || n >= 1000000 then numberToEo y else "") ++ s ++ if r /= 0 then " " ++ numberToEo r else "" where y = n `div` x r = n `mod` x {- Berechnen der 10er Potenz (10^x) -} calcPot :: Integer -> Integer -> Integer calcPot n x | n `div` 10 ^ x < 1000 = x | otherwise = calcPot n $x + 3 {- Bonusaufgabe - Berechne für mil... -} calcMil :: Integer -> Integer -> String calcMil n x | x == 6 = calc n y $evalMultiply n y " miliono" | x == 9 = calc n y $evalMultiply n y " miliardo" | even x = calcMilBig n x y "iliono" | otherwise = calcMilBig n x y "iliardo" where y = 10 ^ x {- Hilfsfunktion -} calcMilBig :: Integer -> Integer -> Integer -> String -> String calcMilBig n x y s = calc n y $evalMultiply n y $" " ++ numberToEo (x `div` 6) ++ s {- j oder kein j - Das ist hier die Frage -} evalMultiply :: Integer -> Integer -> String -> String evalMultiply n x t = if n `div` x /= 1 then t ++ "j" else t {-TTEW-}