mirror of
https://github.com/mx42/adventofcode.git
synced 2026-01-14 05:49:52 +01:00
Add 2020 day 6
This commit is contained in:
2131
haskellAoC/inputs/2020/06
Normal file
2131
haskellAoC/inputs/2020/06
Normal file
File diff suppressed because it is too large
Load Diff
28
haskellAoC/src/Y2020/Day06.hs
Normal file
28
haskellAoC/src/Y2020/Day06.hs
Normal 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
|
||||||
@@ -5,6 +5,7 @@ import Y2020.Day02
|
|||||||
import Y2020.Day03
|
import Y2020.Day03
|
||||||
import Y2020.Day04
|
import Y2020.Day04
|
||||||
import Y2020.Day05
|
import Y2020.Day05
|
||||||
|
import Y2020.Day06
|
||||||
|
|
||||||
|
|
||||||
year2020 :: String -> [String] -> (String, String)
|
year2020 :: String -> [String] -> (String, String)
|
||||||
@@ -13,3 +14,4 @@ year2020 "02" = y20day02
|
|||||||
year2020 "03" = y20day03
|
year2020 "03" = y20day03
|
||||||
year2020 "04" = y20day04
|
year2020 "04" = y20day04
|
||||||
year2020 "05" = y20day05
|
year2020 "05" = y20day05
|
||||||
|
year2020 "06" = y20day06
|
||||||
|
|||||||
Reference in New Issue
Block a user