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 x = helper (x + 1) 0 where helper x c | mod x 2 == 0 = helper (div x 2) (c + 1) | otherwise = c {-H1.1c)-} myFst :: Integer -> Integer myFst x = helper (x + 1) where helper x | mod x 2 == 0 = helper (div x 2) | otherwise = div (x - 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-} joins :: String -> String -> String joins s1 s2 = if (s1 == "" || s2 == "") then s1 ++ s2 else s1 ++ " " ++ s2 poof :: String -> Bool -> String poof s b = if b then s else "" blockParse :: Integer -> Bool -> [String] blockParse i b = if b then [] else [(poof (digitToEo div100) (div100 > 1)) ++ (poof "cent" (div100 >= 1))] ++ [(poof (digitToEo divmod100) (divmod100 > 1)) ++ (poof "dek" (divmod100 >= 1))] ++ [poof (digitToEo mod10) (mod10 > 0)] where div100 = div i 100 divmod100 = div (mod i 100) 10 mod10 = mod i 10 blockSuffix :: Integer -> Bool -> String blockSuffix 0 b = [] blockSuffix n True = (blockSuffix n False) ++ "j" blockSuffix n False | n==1 = "mil" | n==2 = "miliono" | n==3 = "miliardo" | mod n 2 == 0 = bPJ n ++ "iliono" | mod n 2 == 1 = bPJ (n-1) ++ "iliardo" where bPJ n = (foldr joins "" (blockParse (div n 2) False)) parse :: Integer -> Integer -> [String] -> [String] parse step i out | i >= 1000 = parse (step + 1) (div i 1000) extension | otherwise = extension where mod1000 = mod i 1000 extension = (blockParse mod1000 (mod1000 * step == 1)) ++ [poof (blockSuffix step (step > 1 && mod1000 > 1)) (mod1000 > 0)] ++ out numberToEo :: Integer -> String numberToEo 0 = digitToEo 0 numberToEo n = foldr joins "" (parse 0 n []) {-TTEW-}