From 7afe4dd84c0cd3415166a48d9c320072f967acfd Mon Sep 17 00:00:00 2001 From: EEva Date: Fri, 19 Jul 2019 18:56:37 +0300 Subject: [PATCH] Better main --- src/Caesar.hs | 5 +++-- src/Main.hs | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Caesar.hs b/src/Caesar.hs index e00fa58..5a2544f 100644 --- a/src/Caesar.hs +++ b/src/Caesar.hs @@ -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) diff --git a/src/Main.hs b/src/Main.hs index 028f914..d21afbd 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -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)