module Exercise01 where import Test.QuickCheck {-H1.1a)-} myPair :: Integer -> Integer -> Integer myPair x y | x >= 0 && y >= 0 = (2 ^ y) * (2 * x + 1) - 1 {-H1.1b)-} mySnd :: Integer -> Integer mySnd x | x >= 0 = mySndHelper (div (x + 1) (2 * myFst x + 1)) 0 -- 2^x, 0 -> x mySndHelper :: Integer -> Integer -> Integer mySndHelper x y | x == 1 = y mySndHelper x y = mySndHelper (div x 2) (y + 1) {-H1.1c)-} myFst :: Integer -> Integer myFst x | x >= 0 = myFstHelper (x + 1) -- (2^y)(2x+1) -> x myFstHelper :: Integer -> Integer myFstHelper x | even x = myFstHelper (div x 2) myFstHelper x | x > 0 = div (x - 1) 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-} digitToEoExp :: Integer -> String digitToEoExp 1 = "m" digitToEoExp 10 = "dek" digitToEoExp x = digitToEo x numberToEo :: Integer -> String numberToEo 0 = "nul" numberToEo n = unwords (filter (/="") [threeDigitToEoExp x (mod (div n (10^(3*x))) 1000) | x <- reverse [0..21]]) threeDigitToEoExp :: Integer -> Integer -> String threeDigitToEoExp e 0 = "" threeDigitToEoExp 0 x = threeDigitToEo x threeDigitToEoExp 1 x = if x == 1 then "mil" else threeDigitToEo x ++ " mil" threeDigitToEoExp e x = threeDigitToEo x ++ " " ++ digitToEoExp (div e 2) ++ (if even (mod e 2) then "iliono" else "iliardo") ++ (if x > 1 then "j" else "") threeDigitToEo :: Integer -> String threeDigitToEo n | n < 10 = digitToEo n threeDigitToEo n | n < 100 = (if n >= 20 then digitToEo (div n 10) else "") ++ "dek" ++ (if mod n 10 > 0 then " " ++ threeDigitToEo (mod n 10) else "") threeDigitToEo n = (if n >= 200 then digitToEo (div n 100) else "") ++ "cent" ++ (if mod n 100 > 0 then " " ++ threeDigitToEo (mod n 100) else "") {-TTEW-}