mirror of
https://github.com/mx42/adventofcode.git
synced 2026-01-14 13:59:51 +01:00
Add 2020 day 10
This commit is contained in:
93
haskellAoC/inputs/2020/10
Normal file
93
haskellAoC/inputs/2020/10
Normal file
@@ -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
|
||||
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