module Exercise01 where import Test.QuickCheck import Data.List {-H1.1a)-} myPair :: Integer -> Integer -> Integer myPair x y = (2^y)*(2*x+1)-1 {-H1.1b)-} mySnd :: Integer -> Integer mySnd p | even p = 0 | otherwise = mySnd (p `div` 2) + 1 {-H1.1c)-} myFst :: Integer -> Integer myFst p = ((p + 1) `div` 2 ^ mySnd p - 1) `div` 2 {-H1.1d)-} prop_myPair :: Integer -> Integer -> Integer -> Property prop_myPair p x y = p >= 0 && x >= 0 && y >= 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-} numberToEo :: Integer -> String numberToEo 0 = "nul" numberToEo n = init $ getString n 0 getString :: Integer -> Integer -> String getString 0 _ = "" getString 1 3 = "mil " getString x p = getString (x `div` 10) (p + 1) ++ if pm == 0 then if xmmm > 0 then getDigit 0 " " ++ posToEo (p `div` 3) xmmm else "" else if xm > 0 then getDigit 1 "" ++ if pm == 1 then "dek " else "cent " else "" where pm = p `mod` 3 xm = x `mod` 10 xmmm = x `mod` 1000 getDigit n s = if xm > n then digitToEo xm ++ s else "" posToEo :: Integer -> Integer -> String posToEo 0 _ = "" posToEo 1 _ = "mil " posToEo p x = (if p < 4 then "m" else if p < 20 then digitToEo $ p `div` 2 else "dek") ++ (if even p then "iliono" else "iliardo") ++ if x > 1 then "j " else " " {-TTEW-}