module Exercise01 where import Test.QuickCheck ((==>), Property ) {-H1.1a)-} myPair :: Integer -> Integer -> Integer myPair x y = (2 ^ y) * (2 * x + 1) - 1 {-H1.1b)-} -- helper function that does the actual math countDivs :: Integer -> Integer -> Integer countDivs n i | n `mod` 2 == 0 = countDivs (n `div` 2) (i + 1) | otherwise = i mySnd :: Integer -> Integer mySnd n = countDivs (n + 1) 0 {-H1.1c)-} myFst :: Integer -> Integer myFst n = (((n + 1) `div` (2 ^ (mySnd n))) - 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" {- BACKUP strIf :: Bool -> String -> String strIf b str = if b then str else "" threeDigitNumberToEo :: Integer -> String threeDigitNumberToEo n = strIf (div100 > 1) (digitToEo div100) ++ strIf nBEH "cent" ++ strIf (sndDigit > 0 && nBEH) " " ++ strIf (sndDigit > 1) (digitToEo sndDigit) ++ strIf (sndDigit >= 1) "dek" ++ strIf (mod10gZ && n `div` 10 > 0) " " ++ strIf mod10gZ (digitToEo mod10) where nBEH = n >= 100 sndDigit = (n `mod` 100) `div` 10 mod10 = n `mod` 10 div100 = n `div` 100 mod10gZ = mod10 > 0 milPrefix :: Integer -> String milPrefix 10 = "dek" milPrefix n = digitToEo n threeDigitPartToEo :: Integer -> Integer -> String threeDigitPartToEo 0 p = "" threeDigitPartToEo n p = threeDigitNumberToEo n ++ " " ++ (if p < 2 then "m" else milPrefix ((p `div` 2) + 1)) ++ (if even p then "iliono" else "iliardo") ++ strIf (n > 1) "j" recNumberToEo :: Integer -> Integer -> String recNumberToEo n p = strIf div1000GZ (recNumberToEo div1000 (p + 1)) ++ strIf (div1000GZ && mod1000 > 0) " " ++ threeDigitPartToEo mod1000 p where div1000 = n `div` 1000 div1000GZ = div1000 > 0 mod1000 = n `mod` 1000 numberToEo :: Integer -> String numberToEo 0 = "nul" numberToEo n = recNumberToEo (n `div` 1000000) 0 ++ strIf (n > 1000000 && modMil > 0) " " ++ strIf (div1000 > 1) (threeDigitNumberToEo div1000 ++ " ") ++ strIf nGT "mil" ++ strIf (mod1000 > 0 && nGT) " " ++ threeDigitNumberToEo mod1000 where modMil = n `mod` 1000000 nGT = modMil >= 1000 div1000 = modMil `div` 1000 mod1000 = modMil `mod` 1000 BACKUP -} {-WETT-} strIf :: Bool -> String -> String strIf b str = if b then str else "" threeDigitNumberToEo :: Integer -> String threeDigitNumberToEo n = strIf (div100 > 1) (digitToEo div100) ++ strIf nBEH "cent" ++ strIf (sndDigit > 0 && nBEH) " " ++ strIf (sndDigit > 1) (digitToEo sndDigit) ++ strIf (sndDigit >= 1) "dek" ++ strIf (mod10gZ && n `div` 10 > 0) " " ++ strIf mod10gZ (digitToEo mod10) where nBEH = n >= 100 sndDigit = (n `mod` 100) `div` 10 mod10 = n `mod` 10 div100 = n `div` 100 mod10gZ = mod10 > 0 milPrefix :: Integer -> String milPrefix 10 = "dek" milPrefix n = digitToEo n threeDigitPartToEo :: Integer -> Integer -> String threeDigitPartToEo 0 p = "" threeDigitPartToEo n p = threeDigitNumberToEo n ++ " " ++ (if p < 2 then "m" else milPrefix ((p `div` 2) + 1)) ++ (if even p then "iliono" else "iliardo") ++ strIf (n > 1) "j" recNumberToEo :: Integer -> Integer -> String recNumberToEo n p = strIf div1000GZ (recNumberToEo div1000 (p + 1)) ++ strIf (div1000GZ && mod1000 > 0) " " ++ threeDigitPartToEo mod1000 p where div1000 = n `div` 1000 div1000GZ = div1000 > 0 mod1000 = n `mod` 1000 numberToEo :: Integer -> String numberToEo 0 = "nul" numberToEo n = recNumberToEo (n `div` 1000000) 0 ++ strIf (n > 1000000 && modMil > 0) " " ++ strIf (div1000 > 1) (threeDigitNumberToEo div1000 ++ " ") ++ strIf nGT "mil" ++ strIf (mod1000 > 0 && nGT) " " ++ threeDigitNumberToEo mod1000 where modMil = n `mod` 1000000 nGT = modMil >= 1000 div1000 = modMil `div` 1000 mod1000 = modMil `mod` 1000 {-TTEW-}