Add 2020 day 6

This commit is contained in:
Xavier Morel
2020-12-07 10:58:50 +01:00
parent 45ef557843
commit c8a5509adf
3 changed files with 2161 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
module Y2020.Day06 (y20day06) where
import Data.List.Split
import Data.List
countUniques :: String -> Int
countUniques input = uniq
where uniq = length $ group $ sort input'
input' = filter (/= '\n') input
keepCommons :: [Char] -> [Char] -> [Char]
keepCommons [] _ = []
keepCommons _ [] = []
keepCommons (x:xs) (y:ys)
| x == y = x:(keepCommons xs ys)
| x < y = keepCommons xs (y:ys)
| x > y = keepCommons (x:xs) ys
countDups :: String -> Int
countDups input = length $ dups
where (h:t) = map sort $ lines input
dups = foldl keepCommons h t
y20day06 :: [String] -> (String, String)
y20day06 input = (part1, part2)
where part1 = show $ sum $ map countUniques groups
part2 = show $ sum $ map countDups groups
groups = splitOn "\n\n" $ unlines input

View File

@@ -5,6 +5,7 @@ import Y2020.Day02
import Y2020.Day03
import Y2020.Day04
import Y2020.Day05
import Y2020.Day06
year2020 :: String -> [String] -> (String, String)
@@ -13,3 +14,4 @@ year2020 "02" = y20day02
year2020 "03" = y20day03
year2020 "04" = y20day04
year2020 "05" = y20day05
year2020 "06" = y20day06