From 4dec21f362c03136e9811a4f4c162fcd8c50544e Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Thu, 2 Dec 2021 17:39:03 +0100 Subject: Added day 10 --- day3/__init__.py | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 day3/__init__.py (limited to 'day3/__init__.py') 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 @@ -from functools import reduce -from typing import List, Generator - -from aoc import BaseAssignment - - -class Assignment(BaseAssignment): - def read_input(self, example = False) -> List: - return list(super().read_input(example)) - - def slope(self, input: List, dx: int, dy: int) -> Generator: - for y, row in enumerate(input[::dy]): - x = (y * dx) % len(row) - yield (x, y) - - def get_trees_for_slope(self, input: List, dx: int, dy: int): - trees = 0 - - for x, y in self.slope(input, dx, dy): - if x == 0 and y == 0: - continue - - if (input[y * dy][x]) == '#': - trees += 1 - - return trees - - - -class AssignmentOne(Assignment): - def run(self, input: List): - return self.get_trees_for_slope(input, 3, 1) - -class AssignmentTwo(Assignment): - def run(self, input: List): - return reduce(lambda accumulator, value: accumulator * value, [ - self.get_trees_for_slope(input, 1, 1), - self.get_trees_for_slope(input, 3, 1), - self.get_trees_for_slope(input, 5, 1), - self.get_trees_for_slope(input, 7, 1), - self.get_trees_for_slope(input, 1, 2), - ]) - -- cgit v1.2.3