From e40944b22d2e1b4458dcc53b3de9e9376ed1c1d3 Mon Sep 17 00:00:00 2001 From: Sloane Perrault Date: Wed, 21 Sep 2022 09:19:52 -0400 Subject: [PATCH] solve: day 6 - solve: day 6, part 1 - solve: day 6, part 2 --- 2020/06/day6.hs | 10 ++++++++++ 2020/06/part1.hs | 10 ++++++++++ 2020/06/part2.hs | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 2020/06/day6.hs create mode 100755 2020/06/part1.hs create mode 100755 2020/06/part2.hs 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