summaryrefslogtreecommitdiffstats
path: root/day9
diff options
context:
space:
mode:
Diffstat (limited to 'day9')
-rw-r--r--day9/__init__.py63
-rw-r--r--day9/example.txt20
-rw-r--r--day9/input.txt1000
3 files changed, 0 insertions, 1083 deletions
diff --git a/day9/__init__.py b/day9/__init__.py
deleted file mode 100644
index 0cf3770..0000000
--- a/day9/__init__.py
+++ /dev/null
@@ -1,63 +0,0 @@
1from typing import Any, Iterator, List
2
3from aoc import BaseAssignment
4
5
6class Assignment(BaseAssignment):
7 def __init__(self, path, preamble_length=25):
8 super().__init__(path)
9 self.preamble_length = int(preamble_length)
10
11 def read_input(self, example=False) -> List:
12 return list(super(Assignment, self).read_input(example))
13
14 def parse_item(self, item: str) -> Any:
15 return int(item)
16
17
18class AssignmentOne(Assignment):
19 def find_invalid(self, input: List, preamble_length: int = 25) -> int:
20 preamble = sorted(input[:preamble_length])
21 to_check = input[preamble_length]
22
23 front_position = 0
24 end_position = preamble_length - 1
25
26 while True:
27 if front_position is end_position:
28 return to_check
29
30 sum = preamble[front_position] + preamble[end_position]
31
32 if sum > to_check:
33 end_position -= 1
34 elif sum < to_check:
35 front_position += 1
36 else:
37 break
38
39 return self.find_invalid(input[1:], preamble_length=preamble_length)
40
41 def run(self, input: List) -> int:
42 return self.find_invalid(
43 input, preamble_length=int(self.preamble_length))
44
45
46class AssignmentTwo(AssignmentOne):
47 def find_weakness(self, input: List, invalid_nr: int) -> int:
48 for index, current_num in enumerate(input):
49 if index < 2:
50 continue
51
52 items_to_check = input[:index]
53 sum_list = sum(items_to_check)
54
55 if sum_list > invalid_nr:
56 break
57 elif sum_list == invalid_nr:
58 return min(items_to_check) + max(items_to_check)
59
60 return self.find_weakness(input[1:], invalid_nr)
61
62 def run(self, input: List) -> int:
63 return self.find_weakness(input, super().run(input))
diff --git a/day9/example.txt b/day9/example.txt
deleted file mode 100644
index cda4246..0000000
--- a/day9/example.txt
+++ /dev/null
@@ -1,20 +0,0 @@
135
220
315
425
547
640
762
855
965
1095
11102
12117
13150
14182
15127
16219
17299
18277
19309
20576 \ No newline at end of file
diff --git a/day9/input.txt b/day9/input.txt
deleted file mode 100644
index e9932d5..0000000
--- a/day9/input.txt
+++ /dev/null
@@ -1,1000 +0,0 @@
118
219
346
414
529
645
740
847
925
1043
1136
1222
1321
144
1532
1633
1737
1838
1926
202
2142
2215
235
2413
2531
269
276
2830
297
3014
3110
328
3369
3411
3512
3625
3716
3817
3922
4019
4118
4220
4351
4421
4524
4623
4726
4815
4960
5013
5129
5227
5344
5442
5528
5638
5730
5836
5931
6032
6133
6234
6335
6437
6555
6639
6740
6870
6941
7043
7178
7258
7373
74101
7560
7656
7757
7875
7959
8067
8171
8261
8368
84110
8569
8680
8772
88112
8976
9079
91144
92129
93114
9484
9599
96113
97132
98115
99148
100116
101118
102120
103128
104126
105187
106130
107190
108152
109229
110141
111151
112155
113299
114209
115163
116239
117183
118197
119331
120212
121228
122270
123231
124234
125236
126244
127246
128355
129256
130392
131271
132342
133292
134360
135296
136306
137318
138346
139602
140375
141380
142395
143534
144456
145440
146459
147470
148502
149478
150480
151490
152517
153527
154548
155563
1561082
1571136
158896
1591044
160614
161693
162698
163988
164755
1651065
1661352
167835
168899
169915
170942
171929
1721173
173958
1741043
175970
1761007
1771075
1781090
1791529
1801750
1811663
1821307