Skip to content

Instantly share code, notes, and snippets.

@louy2 louy2/desert_park.hs
Last active Feb 21, 2019

Embed
What would you like to do?
問題「砂漠の公園」 | エンジニアが死滅シタ世界 〜アンドロイドとふたりぼっちで生きろ〜
import Data.List (elemIndex)
import Data.Maybe (fromJust, isJust)
p :: [String] -> [[Maybe Int]]
p = fmap (fmap d)
where
d 'W' = Just 2
d 'D' = Just 1
d 'L' = Just 0
d _ = Nothing
f :: String -> String
f input = unwords . fmap show $
let scores = p . drop 1 . lines $ input
s = fromJust . (elemIndex =<< maximum) . fmap (sum . fmap fromJust . filter isJust) $ scores
t = sum . fmap fromJust . filter isJust . (!! s) $ scores
w = length . filter (== Just 2) . (!! s) $ scores
d = length . filter (== Just 1) . (!! s) $ scores
l = length . filter (== Just 0) . (!! s) $ scores
in [s + 1, t, w, d, l]
main :: IO ()
main = interact f
test1 :: String
test1 = "3\n-DW\nD-D\nLD-\n"
test2 :: String
test2 = "10\n-WLDWWDWWW\nL-WDWWWLWW\nWL-LWWLWWD\nDDW-WWDWWW\nLLLL-LLLWW\nLLLLW-WLLL\nDLWDWL-WLW\nLWLLWWL-WW\nLLLLLWWL-W\nLLDLLWLLL-\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.