Created
May 1, 2015 13:08
-
-
Save lux01/c4d14d61524166832feb to your computer and use it in GitHub Desktop.
Daily Programmer #212 Easy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Implementation of Reddit /r/DailyProgrammer challenge #212 [Easy] | |
-- Rövarspråket | |
import Data.Char (isUpper, toLower) | |
type Consonants = [Char] | |
robberEncode :: Consonants -> String -> String | |
robberEncode cons = concat . map mapper | |
where mapper :: Char -> String | |
mapper c | |
| (toLower c) `elem` cons = [c, 'o', toLower c] | |
| otherwise = [c] | |
robberDecode :: Consonants -> String -> String | |
robberDecode cons [] = [] | |
robberDecode cons (c:cs) | |
| (toLower c) `elem` cons && length cs > 1 = c : robberDecode cons (drop 2 cs) | |
| otherwise = c : robberDecode cons cs | |
swedishConsonants :: Consonants | |
swedishConsonants = "bcdfghjklmnpqrstvwxz" | |
englishConsonants :: Consonants | |
englishConsonants = swedishConsonants |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment