Skip to content

Instantly share code, notes, and snippets.

@louy2
Last active February 21, 2019 11:34
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 louy2/91ee812843b6c6ca43bc1cf3a792fed7 to your computer and use it in GitHub Desktop.
Save louy2/91ee812843b6c6ca43bc1cf3a792fed7 to your computer and use it in GitHub Desktop.
問題「砂漠の公園」 | エンジニアが死滅シタ世界 〜アンドロイドとふたりぼっちで生きろ〜
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