Skip to content

Instantly share code, notes, and snippets.

@iseebi
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 iseebi/5253805 to your computer and use it in GitHub Desktop.
Save iseebi/5253805 to your computer and use it in GitHub Desktop.
すごいHaskell読書会 #7 課題
import Data.Char
import Data.List
import System.Environment
charLen :: (Num a) => Char -> a
charLen c
| (ord c) <= 255 = 1
| otherwise = 2
multibyteStringLen :: (Num a) => String -> a
multibyteStringLen s = sum $ map charLen s
doubleCharLine :: (RealFrac a) => a -> String -> String
doubleCharLine i c = concat $ replicate (ceiling $ i / 2) c
upperLine :: (RealFrac a) => a -> String
upperLine i = "_" ++ (doubleCharLine (i + 4) "人") ++ "_"
lowerLine :: (RealFrac a) => a -> String
lowerLine i = " ̄" ++ (doubleCharLine (i + 4) "Y^") ++ " ̄"
centerLine :: String -> String
centerLine s
| odd (multibyteStringLen s) = "> " ++ s ++ "  <"
| otherwise = "> " ++ s ++ " <"
balloon :: String -> String
balloon s = intercalate "\n" [(upperLine (multibyteStringLen s)), (centerLine s), (lowerLine (multibyteStringLen s))]
sudden :: String -> String
sudden s = balloon $ "突然の" ++ s
main = do
args <- getArgs
putStrLn (sudden $ intercalate " " args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment