mirror of
https://github.com/mx42/adventofcode.git
synced 2026-01-15 06:19:51 +01:00
Add 2020 day 10
This commit is contained in:
19
haskellAoC/src/Y2020/Day10.hs
Normal file
19
haskellAoC/src/Y2020/Day10.hs
Normal file
@@ -0,0 +1,19 @@
|
||||
module Y2020.Day10 (y20day10) where
|
||||
|
||||
import Data.List
|
||||
|
||||
sliding :: [Int] -> [(Int, Int)]
|
||||
sliding (x1:x2:xs) = ((x1, x2):(sliding (x2:xs)))
|
||||
sliding (x1:[]) = ((x1, x1+3):[])
|
||||
sliding [] = []
|
||||
|
||||
combinations :: Int -> Int
|
||||
combinations n = nb !! n
|
||||
where nb = [1, 1, 2, 4, 7, 13]
|
||||
|
||||
y20day10 :: [String] -> (String, String)
|
||||
y20day10 input = (part1, part2)
|
||||
where part1 = show $ product $ map length $ group $ filter (/= 2) $ sort $ diffs
|
||||
part2 = show $ product $ map (combinations . length) $ filter (\(x:_) -> x /= 3) $ group $ diffs
|
||||
input' = sort $ map read input :: [Int]
|
||||
diffs = map (\(a, b) -> b - a) $ (0, head input'):(sliding input')
|
||||
@@ -9,6 +9,7 @@ import Y2020.Day06
|
||||
import Y2020.Day07
|
||||
import Y2020.Day08
|
||||
import Y2020.Day09
|
||||
import Y2020.Day10
|
||||
|
||||
year2020 :: String -> [String] -> (String, String)
|
||||
year2020 "01" = y20day01
|
||||
@@ -20,3 +21,4 @@ year2020 "06" = y20day06
|
||||
year2020 "07" = y20day07
|
||||
year2020 "08" = y20day08
|
||||
year2020 "09" = y20day09
|
||||
year2020 "10" = y20day10
|
||||
|
||||
Reference in New Issue
Block a user