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 z | mod z 2 == 1 = 1 + mySnd ((z - 1) `div` 2) | otherwise = 0 {-H1.1c)-} myFst :: Integer -> Integer myFst z | mod z 2 == 1 = myFst ((z - 1) `div` 2) | otherwise = z `div` 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-} digToEo :: Integer -> String digToEo 0 = "" digToEo 10 = " dek" digToEo n = " " ++ digitToEo n digToEoOne :: Integer -> String digToEoOne 1 = " " digToEoOne n = digToEo n numberToEo :: Integer -> String numberToEo 0 = "nul" numberToEo n = tail $ helper n 0 helper :: Integer -> Integer -> String helper 0 _ = "" helper n e = div n 1000 `helper` (e+1) ++ mod n 1000 `trippletToEo` e trippletToEo :: Integer -> Integer -> String trippletToEo 0 _ = "" trippletToEo 1 1 = " mil" trippletToEo n exponent = hundretsToEo n 0 ++ suffix n exponent hundretsToEo :: Integer -> Integer -> String hundretsToEo 0 _ = "" hundretsToEo n e | e==0 = rest ++ digToEo digit | digit /= 0 = rest ++ digToEoOne digit ++ hundretsSuffix e | otherwise = rest where rest = div n 10 `hundretsToEo` (e+1) digit = n `mod` 10 hundretsSuffix :: Integer -> String hundretsSuffix 1 = "dek" hundretsSuffix 2 = "cent" suffix :: Integer -> Integer -> String suffix n 0 = "" suffix n 1 = " mil" suffix 1 e = suffixBig e suffix n e = suffixBig e ++ "j" suffixBig :: Integer -> String suffixBig 2 = " miliono" suffixBig 3 = " miliardo" suffixBig e | even e = prefix ++ "iliono" | otherwise = prefix ++ "iliardo" where prefix = digToEo $ div e 2 {-TTEW-}