tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
7
Task/Rot-13/Haskell/rot-13-1.hs
Normal file
7
Task/Rot-13/Haskell/rot-13-1.hs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import Data.Char
|
||||
|
||||
rot13 :: Char -> Char
|
||||
rot13 c
|
||||
| toLower c >= 'a' && toLower c <= 'm' = chr (ord c + 13)
|
||||
| toLower c >= 'n' && toLower c <= 'z' = chr (ord c - 13)
|
||||
| otherwise = c
|
||||
23
Task/Rot-13/Haskell/rot-13-2.hs
Normal file
23
Task/Rot-13/Haskell/rot-13-2.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-3.hs
Normal file
3
Task/Rot-13/Haskell/rot-13-3.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