diff --git a/exercises/secret-lang/Secret-lang.hs b/exercises/secret-lang/Secret-lang.hs index 61c1406..3ee5f9b 100644 --- a/exercises/secret-lang/Secret-lang.hs +++ b/exercises/secret-lang/Secret-lang.hs @@ -1,32 +1,58 @@ import Data.Char(toLower) +vowels = "aeiou" isChar :: Char -> Bool -isChar = undefined +isChar char + | toLower char >= 'a' && toLower char <= 'z' = True +isChar _ = False + +isInString :: Char -> String -> Bool +isInString char [] = False +isInString char (first:rest) + | char == first = True + | char /= first = isInString char rest isVowel :: Char -> Bool -isVowel = undefined +isVowel char + | isInString (toLower char) vowels == True = True +isVowel _ = False isConsonant :: Char -> Bool -isConsonant = undefined +isConsonant char + | isVowel char == False && isChar char == True = True + | otherwise = False encode :: String -> String -encode = undefined +encode [] = [] +encode (first:rest) + | isConsonant first == True = first : 'o' : first : (encode rest) + | otherwise = first:(encode rest) -- Bonus #1 encode' :: String -> String -encode' = undefined +encode' [] = [] +encode' (first:rest) + | isConsonant first == True = first : 'o' : toLower first : (encode' rest) + | otherwise = first:(encode' rest) -- Bonus #2 dropN :: Int -> String -> String -dropN = undefined +dropN number [] = [] +dropN 0 string = string +dropN number (first:rest) = dropN (number-1) rest + --Assume we'll be decoding only valid words decode :: String -> String -decode = undefined +decode [] = [] +decode (x : 'o' : y : rest) + | x == y = x : decode (dropN 2 ('o':y:rest)) + | otherwise = x : 'o' : y : (decode (rest)) +decode (first : rest) = first : decode (rest)