Fun with Sum

This commit is contained in:
Martin Potier 2020-12-08 17:20:10 +02:00
parent 207769dccc
commit e387598fd1
No known key found for this signature in database
GPG key ID: D4DD957DBA4AD89E

View file

@ -7,7 +7,9 @@
import Control.Applicative
import Data.Attoparsec.Text (Parser, parseOnly)
import Data.Bool (bool)
import Data.Map (Map)
import Data.Monoid (Sum(..))
import Data.MultiSet (MultiSet)
import Data.Tree (Tree)
import Text.Pretty.Simple
@ -102,7 +104,8 @@ solvePart1 color strs = do
rules <- parseStrs strs
let trees = map (\c -> mkSimpleTree c rules) (filter (/= color) $ M.keys rules)
let containColor = map (elem color) trees
pure $ length $ filter (== True) containColor
pure $ getSum $ foldMap (Sum . bool 0 1) containColor
-- ^^ complicated exp for: pure $ length $ filter (== True) containColor
main :: IO ()
main = do