module Exercise01 where import Test.QuickCheck ((==>), property, Property ) {-H1.1a)-} myPair :: Integer -> Integer -> Integer myPair x y = 2^y*(2*x+1)-1 {-H1.1b)-} mySnd :: Integer -> Integer mySnd x | even x = 0 | odd x = 1 + mySnd(div x 2) {-H1.1c)-} myFst :: Integer -> Integer myFst x = div x (2^(mySnd x + 1)) {-H1.1d)-} prop_myPair :: Integer -> Integer -> Integer -> Property prop_myPair p x y = x>=0 && y>=0 && p>=0 ==> property( 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" digitToEo x | x < 20 = "dek" ++ if mod x 10 /= 0 then " " ++ digitToEo (mod x 10) else "" | x < 100 = digitToEo (div x 10) ++ digitToEo (x - (div x 10 -1) * 10) | x < 200 = "cent" ++ if mod x 100 /= 0 then " " ++ digitToEo (mod x 100) else "" | x < 1000 = digitToEo(div x 100) ++ digitToEo (x - (div x 100 - 1) * 100) | x < 2000 = "mil" ++ if mod x 1000 /= 0 then " " ++ digitToEo (mod x 1000) else "" | x < 1000000 = digitToEo(div x 1000) ++ " " ++ digitToEo (x - (div x 1000 - 1) * 1000) {-WETT-} numberToEo :: Integer -> String numberToEo 0 = "nul" numberToEo 1 = "unu" numberToEo 2 = "du" numberToEo 3 = "tri" numberToEo 4 = "kvar" numberToEo 5 = "kvin" numberToEo 6 = "ses" numberToEo 7 = "sep" numberToEo 8 = "ok" numberToEo 9 = "nau" numberToEo x | x < 20 = fstSmallString "dek" 10 | x < 100 = secSmallString 10 "" | x < 200 = fstSmallString "cent" 100 | x < 1000 = secSmallString 100 "" | x < 2000 = fstSmallString "mil" 1000 | x < 1000000 = secSmallString 1000 " " | nODmod6 /= 0 && nODmod6 <= 3 = bigString "iliono" 0 | otherwise = bigString "iliardo" 3 where n a = div (numberOfdigits x 0 -1 - a) 6 fst3Digits a = div x (10^(n a * 6 + a)) restDigits a = x - fst3Digits a * 10^(n a * 6 + a) nODmod6 = mod (numberOfdigits x 0) 6 fstSmallString name num = name ++ if mod x num /= 0 then " " ++ numberToEo (mod x num) else "" secSmallString num mid = numberToEo (div x num) ++ mid ++ numberToEo (x - (div x num -1) *num) bigString mil a = numberToEo (fst3Digits a) ++ " " ++ (if n a /= 1 then numberToEo (n a) else "m") ++ mil ++ (if fst3Digits a == 1 then "" else "j") ++ (if restDigits a /= 0 then " " ++ numberToEo (restDigits a) else "") numberOfdigits :: Integer -> Integer -> Integer numberOfdigits 0 y = y numberOfdigits x y = numberOfdigits (div x 10) (y+1) {-TTEW-} test :: Integer -> IO () test 0 = return() test n | n >= 0 = do putStrLn (numberToEo n) --test(n - 1) test (div n 10)