Better main
This commit is contained in:
parent
b378d13ebb
commit
7afe4dd84c
2 changed files with 10 additions and 3 deletions
|
@ -4,13 +4,14 @@ import Data.Char
|
|||
import Data.Maybe
|
||||
|
||||
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
wtf = '¿'
|
||||
|
||||
downGrade :: String -> String
|
||||
downGrade = fmap (clip . toUpper)
|
||||
where
|
||||
clip c | elem (toUpper c) alphabet = toUpper c
|
||||
clip ' ' = ' '
|
||||
clip _ = '_'
|
||||
clip _ = wtf
|
||||
|
||||
encode :: Int -> String -> String
|
||||
encode key msg = unwords $ encodeWord key <$> (words $ downGrade msg)
|
||||
|
@ -25,7 +26,7 @@ encodeWord :: Int -> String -> String
|
|||
encodeWord k = fmap (substitute $ mapping k)
|
||||
|
||||
substitute :: [(Char,Char)] -> Char -> Char
|
||||
substitute m e = fromMaybe '_' $ lookup e m
|
||||
substitute m e = fromMaybe wtf $ lookup e m
|
||||
|
||||
mapping :: Int -> [(Char,Char)]
|
||||
mapping k = zip alphabet (alphabet `rotateBy` k)
|
||||
|
|
|
@ -4,4 +4,10 @@ import Caesar
|
|||
|
||||
-- Incredible!
|
||||
main :: IO ()
|
||||
main = putStrLn $ decode 1 $ encode 1 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam rhoncus elit ac nunc ornare fringilla. Sed pharetra eros pulvinar pellentesque aliquam. Donec in pretium elit. Aliquam vulputate tincidunt venenatis. Morbi quis metus nisi. Vestibulum nunc est, fringilla vel posuere sit amet, ultricies at nulla. Nunc bibendum odio vel augue mollis congue. Mauris vitae gravida quam. Vivamus dictum vehicula nisl non egestas. Cras ultrices ullamcorper diam non lacinia. Sed mollis quam augue, ac dictum erat auctor sit amet."
|
||||
main = do
|
||||
let t = "I like strawberries!"
|
||||
putStrLn t
|
||||
putStrLn $ encode 3 t
|
||||
putStrLn $ id' 3 t
|
||||
|
||||
id' n = (decode n) . (encode n)
|
||||
|
|
Loading…
Reference in a new issue