summaryrefslogtreecommitdiffstats
path: root/day1/__init__.py
diff options
context:
space:
mode:
authorGravatar Tom van der Lee <tom@vanderlee.io>2021-12-02 17:39:03 +0100
committerGravatar Tom van der Lee <tom@vanderlee.io>2021-12-02 17:39:03 +0100
commit4dec21f362c03136e9811a4f4c162fcd8c50544e (patch)
treecd90c52c7c936fdbe5fc7f22f3f5bf3240faf9a8 /day1/__init__.py
parent37aa8eec0498d7e8491084711132f16db9129a39 (diff)
download2021-4dec21f362c03136e9811a4f4c162fcd8c50544e.tar.gz
2021-4dec21f362c03136e9811a4f4c162fcd8c50544e.tar.bz2
2021-4dec21f362c03136e9811a4f4c162fcd8c50544e.zip
Added day 10
Diffstat (limited to 'day1/__init__.py')
-rw-r--r--day1/__init__.py28
1 files changed, 11 insertions, 17 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)