1
0
Fork 0

solve: day 6

- solve: day 6, part 1
 - solve: day 6, part 2
This commit is contained in:
Sloane Perrault 2022-09-21 09:19:52 -04:00
parent f0953800c5
commit e40944b22d
3 changed files with 38 additions and 0 deletions

10
2020/06/day6.hs Normal file
View file

@ -0,0 +1,10 @@
module Day6 (lines') where
lines' = joinLines . lines
joinLines = foldl parse [[]]
where
parse [[]] s = [[s]]
parse [a] "" = [[], a]
parse [a] s = [a ++ [s]]
parse (a:as) s = parse [a] s ++ as

10
2020/06/part1.hs Executable file
View file

@ -0,0 +1,10 @@
#!/usr/bin/env runghc
import Day6
import Data.Set (fromList, size)
main = interact (show . solve . parse)
solve = sum . map size
parse = map fromList . lines'

18
2020/06/part2.hs Executable file
View file

@ -0,0 +1,18 @@
#!/usr/bin/env runghc
import Day6
import Data.Set (fromList, size)
main = interact (show . solve . parse)
solve = sum . map countEveryoneYes
parse = lines'
countEveryoneYes :: [String] -> Int
countEveryoneYes group =
length $ filter everyoneYes questions
where
n = length group
questions = ['a'..'z']
everyoneYes q = all (elem q) group