Skip to content

Instantly share code, notes, and snippets.

@yashigani
Last active December 15, 2015 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yashigani/5253683 to your computer and use it in GitHub Desktop.
Save yashigani/5253683 to your computer and use it in GitHub Desktop.
すごいH本読書会 #7 練習問題
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