Solve day 6, parts 1 and 2

main
Gaël Depreeuw 4 years ago
parent 324e47c7b4
commit 04dd9843db
Signed by: Mithror
GPG Key ID: 8AB218ABA4867F78
  1. 2
      AdventOfCode2020.cabal
  2. 2
      Main.hs
  3. 2101
      input/day6
  4. 27
      src/Day6.hs

@ -17,7 +17,7 @@ maintainer: gael@depreeuw.dev
extra-source-files: CHANGELOG.md, README.md
library
exposed-modules: Day1, Day2, Day3, Day4, Day5
exposed-modules: Day1, Day2, Day3, Day4, Day5, Day6
-- other-modules:
-- other-extensions:
build-depends: base ^>=4.13.0.0

@ -5,6 +5,7 @@ import Day2 (day2)
import Day3 (day3)
import Day4 (day4)
import Day5 (day5)
import Day6 (day6)
main :: IO ()
main = do
@ -13,3 +14,4 @@ main = do
day3
day4
day5
day6

File diff suppressed because it is too large Load Diff

@ -0,0 +1,27 @@
module Day6 (day6) where
import Data.List (foldl', intersect)
import qualified Data.Set as S
separateForms :: [String] -> [[String]]
separateForms s = let (a, b) = foldl' go ([], []) s in b ++ [a]
where
go (l, t) "" = ([], t ++ [l])
go (l, t) xs = (l ++ [xs], t)
countYesses :: [String] -> Int
countYesses = length . S.fromList . concat
countYesses' :: [String] -> Int
countYesses' = length . foldl' go ['a' .. 'z']
where
go b a = b `intersect` a
day6 :: IO ()
day6 = do
r <- readFile "./input/day6"
let m = separateForms . lines $ r
putStr "[Day 6-1] # yess: "
print . sum . map countYesses $ m
putStr "[Day 6-2] # yess: "
print . sum . map countYesses' $ m
Loading…
Cancel
Save