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 p = if even p then 0 else 1 + mySnd (div p 2) {-H1.1c)-} myFst :: Integer -> Integer myFst p = div (div (p + 1) (2 ^ mySnd p) - 1) 2 {-H1.1d)-} prop_myPair :: Integer -> Integer -> Integer -> Property prop_myPair p x y = p >=0 && x >= 0 && y >= 0 ==> p == myPair x y {-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-} eoInfix :: Integer -> String eoInfix 1 = " mil" eoInfix 2 = " miliono" eoInfix 3 = " miliardo" eoInfix 20 = " dekiliono" eoInfix 21 = " dekiliardo" eoInfix n = " " ++ digitToEo (div n 2) ++ if even n then "iliono" else "iliardo" numberToEo :: Integer -> String numberToEo n = numberToEoHelper n 1 numberToEoHelper :: Integer -> Integer -> String numberToEoHelper 0 1 = "nul" numberToEoHelper n k | beginning == 0 = numberToEoLessThan1000 rest | beginning == 1 && k == 1 = "mil" ++ lastThreeDigits | mod beginning 1000 == 0 = numberToEoHelper beginning (k + 1) ++ lastThreeDigits | otherwise = numberToEoHelper beginning (k + 1) ++ eoInfix k ++ j ++ lastThreeDigits where beginning = div n 1000 rest = mod n 1000 lastThreeDigits = if rest == 0 then "" else " " ++ numberToEoLessThan1000 rest j = if k > 1 && mod beginning 1000 > 1 then "j" else "" numberToEoLessThan1000 :: Integer -> String numberToEoLessThan1000 n | n == 0 = "" | n < 10 = digitToEo n | otherwise = if d == 1 then suffix else digitToEo d ++ suffix where l = if n < 100 then 10 else 100 d = div n l rest = mod n l space = if rest == 0 then "" else " " suffix = (if l == 10 then "dek" else "cent") ++ space ++ numberToEoLessThan1000 rest {-TTEW-}