Fun with Sum
This commit is contained in:
parent
207769dccc
commit
e387598fd1
1 changed files with 4 additions and 1 deletions
|
@ -7,7 +7,9 @@
|
||||||
|
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
import Data.Attoparsec.Text (Parser, parseOnly)
|
import Data.Attoparsec.Text (Parser, parseOnly)
|
||||||
|
import Data.Bool (bool)
|
||||||
import Data.Map (Map)
|
import Data.Map (Map)
|
||||||
|
import Data.Monoid (Sum(..))
|
||||||
import Data.MultiSet (MultiSet)
|
import Data.MultiSet (MultiSet)
|
||||||
import Data.Tree (Tree)
|
import Data.Tree (Tree)
|
||||||
import Text.Pretty.Simple
|
import Text.Pretty.Simple
|
||||||
|
@ -102,7 +104,8 @@ solvePart1 color strs = do
|
||||||
rules <- parseStrs strs
|
rules <- parseStrs strs
|
||||||
let trees = map (\c -> mkSimpleTree c rules) (filter (/= color) $ M.keys rules)
|
let trees = map (\c -> mkSimpleTree c rules) (filter (/= color) $ M.keys rules)
|
||||||
let containColor = map (elem color) trees
|
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 :: IO ()
|
||||||
main = do
|
main = do
|
||||||
|
|
Loading…
Reference in a new issue