summaryrefslogtreecommitdiffstats
path: root/day3/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'day3/__init__.py')
-rw-r--r--day3/__init__.py43
1 files changed, 0 insertions, 43 deletions
diff --git a/day3/__init__.py b/day3/__init__.py
deleted file mode 100644
index 4954c15..0000000
--- a/day3/__init__.py
+++ /dev/null
@@ -1,43 +0,0 @@
1from functools import reduce
2from typing import List, Generator
3
4from aoc import BaseAssignment
5
6
7class Assignment(BaseAssignment):
8 def read_input(self, example = False) -> List:
9 return list(super().read_input(example))
10
11 def slope(self, input: List, dx: int, dy: int) -> Generator:
12 for y, row in enumerate(input[::dy]):
13 x = (y * dx) % len(row)
14 yield (x, y)
15
16 def get_trees_for_slope(self, input: List, dx: int, dy: int):
17 trees = 0
18
19 for x, y in self.slope(input, dx, dy):
20 if x == 0 and y == 0:
21 continue
22
23 if (input[y * dy][x]) == '#':
24 trees += 1
25
26 return trees
27
28
29
30class AssignmentOne(Assignment):
31 def run(self, input: List):
32 return self.get_trees_for_slope(input, 3, 1)
33
34class AssignmentTwo(Assignment):
35 def run(self, input: List):
36 return reduce(lambda accumulator, value: accumulator * value, [
37 self.get_trees_for_slope(input, 1, 1),
38 self.get_trees_for_slope(input, 3, 1),
39 self.get_trees_for_slope(input, 5, 1),
40 self.get_trees_for_slope(input, 7, 1),
41 self.get_trees_for_slope(input, 1, 2),
42 ])
43