This code is hilarious
This commit is contained in:
shu 2020-12-10 08:05:45 +01:00
parent 54c97ceb71
commit 44a48767ef
4 changed files with 158 additions and 0 deletions

21
2020/day10/day10.hs Normal file
View File

@ -0,0 +1,21 @@
import Control.Arrow
import Control.Monad
import Data.List
main :: IO ()
main = do
input <- map read . lines <$> readFile "input"
print $ (product . map length . group . sort . jolts) input
print $
(product . map (arrangements . sum) . filter (elem 1) . group . jolts) input
arrangements :: Int -> Int
arrangements n =
length $
filter (== n) $ map sum $ nub $ map (filter (/= 0)) $ replicateM n [0 .. 3]
jolts :: [Int] -> [Int]
jolts =
map (uncurry subtract) .
ap zip tail .
uncurry (++) . (id &&& (flip (:) [] . (+ 3) . last)) . (:) 0 . sort

95
2020/day10/input Normal file
View File

@ -0,0 +1,95 @@
99
3
1
11
48
113
131
43
82
19
4
153
105
52
56
109
27
119
147
31
34
13
129
17
61
10
29
24
12
104
152
103
80
116
79
73
21
133
44
18
74
112
136
30
146
100
39
130
91
124
70
115
81
28
151
2
122
87
143
62
7
126
95
75
20
123
63
125
53
45
141
14
67
69
60
114
57
142
150
42
78
132
66
88
140
139
106
38
85
37
51
94
98
86
68

11
2020/day10/testinput Normal file
View File

@ -0,0 +1,11 @@
16
10
15
5
1
11
7
19
6
12
4

31
2020/day10/testinput2 Normal file
View File

@ -0,0 +1,31 @@
28
33
18
42
31
14
46
20
48
47
24
23
49
45
19
38
39
11
1
32
25
35
8
17
7
9
4
2
34
10
3