Finished day 6

This commit is contained in:
Martin Potier 2020-12-07 20:32:40 +02:00
parent b344686716
commit 97f5bd536f

View file

@ -43,11 +43,13 @@ paragraphs strs = go (strs, [])
solvePart1 :: [String] -> Int
solvePart1 = sum . (map countUniqueAnswers) . paragraphs
allAnsweredX :: Char -> [[String]] -> Bool
allAnsweredX c = all (any (== c))
allAnsweredX :: Char -> [[String]] -> [Bool]
allAnsweredX c = map (all (any (== c)))
solvePart2 :: [String] -> [Bool]
solvePart2 = allAnsweredX 'a' . paragraphs
solvePart2 :: [String] -> Int
solvePart2 strs = length . (filter (== True)) $ concat $ map (\x -> (allAnsweredX x . paragraphs) strs) ['a'..'z']
main :: IO ()
main = do
@ -63,7 +65,8 @@ main = do
input <- lines <$> readFile "day6/input"
print $ solvePart1 input
putStrLn "Day 6 - Part 2 : solving test"
print $ paragraphs exampleData
print $ solvePart2 exampleData
-- putStrLn "Day 6 - Part 2 : solving input"
-- print $ solvePart2 input
putStrLn "Day 6 - Part 2 : solving input"
print $ solvePart2 input