summaryrefslogtreecommitdiffstats
path: root/day1/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'day1/__init__.py')
-rw-r--r--day1/__init__.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/day1/__init__.py b/day1/__init__.py
new file mode 100644
index 0000000..ce728cc
--- /dev/null
+++ b/day1/__init__.py
@@ -0,0 +1,36 @@
1from typing import Iterator, List
2
3from aoc import AssignmentBase
4
5
6class Assignment(AssignmentBase):
7 def parse_item(self, item: str) -> int:
8 return int(item)
9
10 def read_input(self, example = False) -> List[int]:
11 return sorted(super().read_input(example))
12
13class AssignmentOne(Assignment):
14 def run(self, input: List) -> int:
15 front_position = 0
16 end_position = -1
17
18 while True:
19 sum = input[front_position] + input[end_position]
20
21 if sum > 2020:
22 end_position -= 1
23 elif sum < 2020:
24 front_position += 1
25 else:
26 break
27
28 return input[front_position] * input[end_position]
29
30class AssignmentTwo(Assignment):
31 def run(self, input: List) -> int:
32 for a in input:
33 for b in input:
34 for c in input:
35 if a + b + c == 2020:
36 return a * b * c \ No newline at end of file