Last active
December 15, 2015 11:29
-
-
Save yashigani/5253683 to your computer and use it in GitHub Desktop.
すごいH本読書会 #7 練習問題
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Environment (getArgs) | |
import Prelude hiding (head, tail) | |
import Data.Char (ord) | |
sudden :: String -> String | |
sudden s = unlines [head s, body s, tail s] | |
body :: String -> String | |
body s = "> 突然の" ++ s ++ " <" | |
head :: String -> String | |
head s = "_人人人人" ++ stretch (len s) "人" ++ "人_" | |
tail :: String -> String | |
tail s = " ̄Y^Y^Y^" ++ stretch (len s) "Y^" ++ "Y^ ̄" | |
stretch :: Int -> String -> String | |
stretch len s = concat $ take len $ repeat s | |
len :: String -> Int | |
len s = ceiling $ | |
foldr (\l acc -> acc + if l > 255 then 1 else 0.5) 0 $ map ord s | |
removeWhitespaces :: [String] -> [String] | |
removeWhitespaces xs = map unwords $ map lines xs | |
main = do | |
args <- getArgs | |
mapM_ putStrLn $ map sudden $ removeWhitespaces args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment