September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,20 +1,17 @@
|
|||
import Data.Char (ord, chr, isUpper, isAlpha)
|
||||
import Data.Bool (bool)
|
||||
|
||||
caesar, uncaesar :: Int -> String -> String
|
||||
caesar = (<$>) . tr
|
||||
caesar = fmap . tr
|
||||
|
||||
uncaesar = caesar . negate
|
||||
|
||||
tr :: Int -> Char -> Char
|
||||
tr offset c
|
||||
| isAlpha c = chr $ intAlpha + mod ((ord c - intAlpha) + offset) 26
|
||||
| isAlpha c =
|
||||
let i = ord $ bool 'a' 'A' (isUpper c)
|
||||
in chr $ i + mod ((ord c - i) + offset) 26
|
||||
| otherwise = c
|
||||
where
|
||||
intAlpha =
|
||||
ord
|
||||
(if isUpper c
|
||||
then 'A'
|
||||
else 'a')
|
||||
|
||||
main :: IO ()
|
||||
main = mapM_ print [encoded, decoded]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue