diff --git a/2020/06/day6.hs b/2020/06/day6.hs new file mode 100644 index 0000000..eac7a9f --- /dev/null +++ b/2020/06/day6.hs @@ -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 diff --git a/2020/06/part1.hs b/2020/06/part1.hs new file mode 100755 index 0000000..8240482 --- /dev/null +++ b/2020/06/part1.hs @@ -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' diff --git a/2020/06/part2.hs b/2020/06/part2.hs new file mode 100755 index 0000000..75d6a4e --- /dev/null +++ b/2020/06/part2.hs @@ -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