summaryrefslogtreecommitdiffstats
path: root/day1
diff options
context:
space:
mode:
Diffstat (limited to 'day1')
-rw-r--r--day1/__init__.py28
-rw-r--r--day1/example.txt16
-rw-r--r--day1/input.txt2166
3 files changed, 2004 insertions, 206 deletions
diff --git a/day1/__init__.py b/day1/__init__.py
index cf48f78..bc44089 100644
--- a/day1/__init__.py
+++ b/day1/__init__.py
@@ -8,29 +8,23 @@ class Assignment(BaseAssignment):
8 return int(item) 8 return int(item)
9 9
10 def read_input(self, example = False) -> List[int]: 10 def read_input(self, example = False) -> List[int]:
11 return sorted(super().read_input(example)) 11 return list(super().read_input(example))
12 12
13class AssignmentOne(Assignment): 13class AssignmentOne(Assignment):
14 def run(self, input: List) -> int: 14 def run(self, input: List) -> int:
15 front_position = 0 15 result = 0
16 end_position = -1
17 16
18 while True: 17 for i in range(1, len(input)):
19 sum = input[front_position] + input[end_position] 18 result += 1 if input[i - 1] < input[i] else 0
20 19
21 if sum > 2020: 20 return result
22 end_position -= 1
23 elif sum < 2020:
24 front_position += 1
25 else:
26 break
27 21
28 return input[front_position] * input[end_position]
29 22
30class AssignmentTwo(Assignment): 23class AssignmentTwo(Assignment):
31 def run(self, input: List) -> int: 24 def run(self, input: List) -> int:
32 for a in input: 25 new_input = [
33 for b in input: 26 input[i - 2] + input[i - 1] + input[i]
34 for c in input: 27 for i in range(2, len(input))
35 if a + b + c == 2020: 28 ]
36 return a * b * c \ No newline at end of file 29
30 return AssignmentOne(path='').run(new_input)
diff --git a/day1/example.txt b/day1/example.txt
index 0bb977d..59dad67 100644
--- a/day1/example.txt
+++ b/day1/example.txt
@@ -1,6 +1,10 @@
11721 1199
2979 2200
3366 3208
4299 4210
5675 5200
61456 \ No newline at end of file 6207
7240
8269
9260
10263 \ No newline at end of file
diff --git a/day1/input.txt b/day1/input.txt
index 0546883..523d802 100644
--- a/day1/input.txt
+++ b/day1/input.txt
@@ -1,200 +1,2000 @@
11511 1171
21344 2173
31925 3174
41970 4163
51864 5161
61951 6157
71557 7156
81984 8154
91743 9152
101526 10156
111972 11151
121945 12153
131969 13132
141760 14135
152008 15151
161592 16143
17736 17141
181963 18149
191994 19145
202009 20147
211777 21142
221856 22143
231899 23139
241926 24141
251850 25144
26147
27137
28144
29147
30153
31151
32153
33157
34185
35186
36185
37181
38161
39177
40179
41177
42178
43173
44175
45183
46181
47191
48189
49186
50189
51192
52191
53189
54199
55208
56218
57216
58210
59209
60208
61215
62207
63198
64202
65204
66205
67204
68203
69205
70207
71208
72209
73218
74234
75231
76245
77244
78243
79265
80264
81279
82282
83283
84274
85276
86279
87281
88279
89258
90256
91289
92297
93300
94304
95308
96298
97302
98317
99316
100315
101314
102296
103298
104301
105298
106293
107300
108293
109290
110286
111282
112278
113280
114283
115292
116297
117315
118323
119324
120321
121324
122332
123334
124366
125375
126382
127388
128395
129400
130410
131405
132407
133408
134405
135403
136426
137425
138423
139440
140444
141469
142471
143472
144498
145501
146498
147499
148500
149502
150514
151515
152516
153518
154517
155516
156507
157514
158521
159523
160521
161513
162518
163531
164543
165546
166540
167528
168529
169520
170530
171533
172534
173532
174535
175538
176545
177550
178548
179534
180552
181555
182570
183571
184589
185595