Skip to content

Commit a59c138

Browse files
committed
added part solution for day 10
1 parent 82f4cbf commit a59c138

File tree

2 files changed

+161
-0
lines changed

2 files changed

+161
-0
lines changed

10.hs

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{-# LANGUAGE DeriveGeneric #-}
2+
{-# LANGUAGE TypeApplications #-}
3+
{-# LANGUAGE ScopedTypeVariables #-}
4+
import Lib
5+
import Debug.Trace
6+
import Data.List (sort)
7+
8+
dummyAdapters = [ 16
9+
, 10
10+
, 15
11+
, 5
12+
, 1
13+
, 11
14+
, 7
15+
, 19
16+
, 6
17+
, 12
18+
, 4 ]
19+
20+
dummyAdapters2 = [ 28
21+
, 33
22+
, 18
23+
, 42
24+
, 31
25+
, 14
26+
, 46
27+
, 20
28+
, 48
29+
, 47
30+
, 24
31+
, 23
32+
, 49
33+
, 45
34+
, 19
35+
, 38
36+
, 39
37+
, 11
38+
, 1
39+
, 32
40+
, 25
41+
, 35
42+
, 8
43+
, 17
44+
, 7
45+
, 9
46+
, 4
47+
, 2
48+
, 34
49+
, 10
50+
, 3 ]
51+
52+
main = do
53+
54+
let counts l = map (\x -> (x, length $ filter (==x) l)) [0..3]
55+
calcResult l = snd . head $ scanr (\a (b,l) -> (a ,(b-a):l)) (maximum dummyAdapters + 3,[]) $ sort $ 0:l
56+
dummyResult = calcResult dummyAdapters
57+
print $ counts dummyResult
58+
print $ counts $ calcResult dummyAdapters2
59+
60+
contents <- readFile "10.input"
61+
let adapters = map (read @Int) $ lines contents
62+
print $ counts $ calcResult adapters -- have to add +1 to the count for three, not yet sure why
63+

10.input

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
35
2+
111
3+
135
4+
32
5+
150
6+
5
7+
106
8+
154
9+
41
10+
7
11+
27
12+
117
13+
109
14+
63
15+
64
16+
21
17+
138
18+
98
19+
40
20+
71
21+
144
22+
13
23+
66
24+
48
25+
12
26+
55
27+
119
28+
103
29+
54
30+
78
31+
65
32+
112
33+
39
34+
128
35+
53
36+
140
37+
77
38+
34
39+
28
40+
81
41+
151
42+
125
43+
85
44+
124
45+
2
46+
99
47+
131
48+
59
49+
60
50+
6
51+
94
52+
33
53+
42
54+
93
55+
14
56+
141
57+
92
58+
38
59+
104
60+
9
61+
29
62+
100
63+
52
64+
19
65+
147
66+
49
67+
74
68+
70
69+
84
70+
113
71+
120
72+
91
73+
97
74+
17
75+
45
76+
139
77+
90
78+
116
79+
149
80+
129
81+
87
82+
69
83+
20
84+
24
85+
148
86+
18
87+
58
88+
123
89+
76
90+
118
91+
130
92+
132
93+
75
94+
110
95+
105
96+
1
97+
8
98+
86

0 commit comments

Comments
 (0)