Last active
December 15, 2015 11:29
-
-
Save iseebi/5253805 to your computer and use it in GitHub Desktop.
すごいHaskell読書会 #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 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