Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
11
Task/Rot-13/Haskell/rot-13-1.hs
Normal file
11
Task/Rot-13/Haskell/rot-13-1.hs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import Data.Char (chr, isAlpha, ord, toLower)
|
||||
import Data.Bool (bool)
|
||||
|
||||
rot13 :: Char -> Char
|
||||
rot13 c
|
||||
| isAlpha c = chr $ bool (-) (+) ('m' >= toLower c) (ord c) 13
|
||||
| otherwise = c
|
||||
|
||||
-- Simple test
|
||||
main :: IO ()
|
||||
main = print $ rot13 <$> "Abjurer nowhere"
|
||||
11
Task/Rot-13/Haskell/rot-13-2.hs
Normal file
11
Task/Rot-13/Haskell/rot-13-2.hs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import Data.Char (chr, isAlpha, ord, toLower)
|
||||
import Data.Bool (bool)
|
||||
|
||||
rot13 :: Char -> Char
|
||||
rot13 =
|
||||
let rot = flip ((bool (-) (+) . ('m' >=) . toLower) <*> ord)
|
||||
in (bool <*> chr . rot 13) <*> isAlpha
|
||||
|
||||
-- Simple test
|
||||
main :: IO ()
|
||||
main = print $ rot13 <$> "Abjurer nowhere"
|
||||
23
Task/Rot-13/Haskell/rot-13-3.hs
Normal file
23
Task/Rot-13/Haskell/rot-13-3.hs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import System.Environment
|
||||
import System.IO
|
||||
import System.Directory
|
||||
import Control.Monad
|
||||
|
||||
hInteract :: (String -> String) -> Handle -> Handle -> IO ()
|
||||
hInteract f hIn hOut =
|
||||
hGetContents hIn >>= hPutStr hOut . f
|
||||
|
||||
processByTemp :: (Handle -> Handle -> IO ()) -> String -> IO ()
|
||||
processByTemp f name = do
|
||||
hIn <- openFile name ReadMode
|
||||
let tmp = name ++ "$"
|
||||
hOut <- openFile tmp WriteMode
|
||||
f hIn hOut
|
||||
hClose hIn
|
||||
hClose hOut
|
||||
removeFile name
|
||||
renameFile tmp name
|
||||
|
||||
process :: (Handle -> Handle -> IO ()) -> [String] -> IO ()
|
||||
process f [] = f stdin stdout
|
||||
process f ns = mapM_ (processByTemp f) ns
|
||||
3
Task/Rot-13/Haskell/rot-13-4.hs
Normal file
3
Task/Rot-13/Haskell/rot-13-4.hs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
main = do
|
||||
names <- getArgs
|
||||
process (hInteract (map rot13)) names
|
||||
Loading…
Add table
Add a link
Reference in a new issue