day10: add haskell solution
This commit is contained in:
parent
c40425cb4e
commit
32f676dcd7
4 changed files with 113 additions and 0 deletions
|
@ -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.
|
||||
|
|
2
2020/data/day10.expected
Normal file
2
2020/data/day10.expected
Normal file
|
@ -0,0 +1,2 @@
|
|||
1885
|
||||
2024782584832
|
93
2020/data/day10.input
Normal file
93
2020/data/day10.input
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
|
17
2020/day10/day10.hs
Normal file
17
2020/day10/day10.hs
Normal file
|
@ -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)
|
Loading…
Reference in a new issue