-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay10_Part1.py
155 lines (147 loc) · 1.31 KB
/
Day10_Part1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import collections
# input = """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"""
input = """99
104
120
108
67
136
80
44
129
113
158
157
89
60
138
63
35
57
61
153
116
54
7
22
133
130
5
72
2
28
131
123
55
145
151
42
98
34
140
146
100
79
117
154
9
83
132
45
43
107
91
163
86
115
39
76
36
82
162
6
27
101
150
30
110
139
109
1
64
56
161
92
62
69
144
21
147
12
114
18
137
75
164
33
152
23
68
51
8
95
90
48
29
26
165
81
13
126
14
143
15"""
##Parse the input string into a list of ints. I assume the input is a consistent list of integers evenly separated by newlines.
parsed_input = [int(a) for a in input.splitlines()]
##Sort the list in place
parsed_input.sort()
##Define a diffs list to store the inter-adapter jolt differences. Initialize the array with the difference between 0 and the first adapter.
diffs = [parsed_input[0]]
#Update diffs to store the inter-adapter jolt differences
diffs = diffs + [(parsed_input[i+1]-parsed_input[i]) for i in range(len(parsed_input)-1)]
#Append 3 to the end of the diffs list since the last jolt difference will always be 3
diffs.append(3)
#Define frequencies of the diffs
freqs = collections.Counter(diffs)
#Print the product of the frequency of 1's and the frequency of 3's
print(freqs[1] * freqs[3])