summaryrefslogtreecommitdiffstats
path: root/day3/__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 /day3/__init__.py
parent37aa8eec0498d7e8491084711132f16db9129a39 (diff)
download2021-4dec21f362c03136e9811a4f4c162fcd8c50544e.tar.gz
2021-4dec21f362c03136e9811a4f4c162fcd8c50544e.tar.bz2
2021-4dec21f362c03136e9811a4f4c162fcd8c50544e.zip
Added day 10
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