diff --git a/2020/README.md b/2020/README.md index 34a4d8b..e2cde37 100644 --- a/2020/README.md +++ b/2020/README.md @@ -15,6 +15,7 @@ https://adventofcode.com/2020/ | 7 | `**` | | | | 8 | | `**` | | | 9 | | `**` | | +|10 | | `**` | | |11 | `**` | | | `test.sh` can be used to run all solutions and automatically compares them to (my) puzzle inputs and the expected outputs. diff --git a/2020/data/day10.expected b/2020/data/day10.expected new file mode 100644 index 0000000..477b30f --- /dev/null +++ b/2020/data/day10.expected @@ -0,0 +1,2 @@ +1885 +2024782584832 diff --git a/2020/data/day10.input b/2020/data/day10.input new file mode 100644 index 0000000..6a9eb2f --- /dev/null +++ b/2020/data/day10.input @@ -0,0 +1,93 @@ +80 +87 +10 +122 +57 +142 +134 +59 +113 +139 +101 +41 +138 +112 +46 +96 +43 +125 +36 +54 +133 +17 +42 +98 +7 +114 +78 +67 +77 +28 +149 +58 +20 +105 +31 +19 +18 +27 +40 +71 +117 +66 +21 +72 +146 +90 +97 +94 +123 +1 +119 +30 +84 +61 +91 +118 +2 +29 +104 +73 +13 +76 +24 +148 +68 +111 +131 +83 +49 +8 +132 +9 +64 +79 +124 +95 +88 +135 +3 +51 +39 +6 +60 +108 +14 +35 +147 +89 +34 +65 +50 +145 +128 diff --git a/2020/day10/day10.hs b/2020/day10/day10.hs new file mode 100644 index 0000000..da88b99 --- /dev/null +++ b/2020/day10/day10.hs @@ -0,0 +1,17 @@ +import AoC + +import Data.List + +pairs :: [a] -> [(a, a)] +pairs xs = zipWith (,) xs (tail xs) + +part1 :: [Int] -> Int +part1 = product . map length . group . sort . map (uncurry $ flip (-)) . pairs + +numArrangements :: [Int] -> Int +numArrangements = snd . head . go + where go xs = foldr (\x acc -> (x, sum . map snd . takeWhile (\(y, _) -> x-y <= 3) $ acc) : acc) [(last xs, 1)] $ init xs + +main = runAoC (addPhonePort . sortReverse . (0:) . map read . lines) part1 numArrangements + where addPhonePort (x:xs) = (x+3):x:xs + sortReverse = sortBy (flip compare)