From 35536a73389e9d555e42f9388552b7c43f5c3a8b Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Sat, 12 Dec 2020 03:07:25 +0100 Subject: Added day 3 --- day3/__init__.py | 43 ++++++++ day3/example.txt | 11 ++ day3/input.txt | 323 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 377 insertions(+) create mode 100644 day3/__init__.py create mode 100644 day3/example.txt create mode 100644 day3/input.txt (limited to 'day3') diff --git a/day3/__init__.py b/day3/__init__.py new file mode 100644 index 0000000..4954c15 --- /dev/null +++ b/day3/__init__.py @@ -0,0 +1,43 @@ +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), + ]) + diff --git a/day3/example.txt b/day3/example.txt new file mode 100644 index 0000000..8f551de --- /dev/null +++ b/day3/example.txt @@ -0,0 +1,11 @@ +..##....... +#...#...#.. +.#....#..#. +..#.#...#.# +.#...##..#. +..#.##..... +.#.#.#....# +.#........# +#.##...#... +#...##....# +.#..#...#.# \ No newline at end of file diff --git a/day3/input.txt b/day3/input.txt new file mode 100644 index 0000000..6cfcb73 --- /dev/null +++ b/day3/input.txt @@ -0,0 +1,323 @@ +...#...#....#....##...###....#. +#.#...#...#....#.........#..#.. +.#....##..#.#..##..##.......... +.....#.#.............#..#...... +.......#...#.##.#......#..#.#.. +#.#....#......##........##..... +.....##.#....#..#...#...##...#. +...#...#..#.......#..#...##...# +..........#...........##....... +..#..#..#...................#.. +#..#....#.....##.#.#..........# +.#.##.......###.....#.#...#.... +.#..##....##....#.......#...### +#.#..##...#.#..#............... +.........#....#.......##.#.#... +...###...##....##...#..##.#..#. +....#.........#..#...#.......#. +....................#..#.#.#... +..#....#..........#...........# +.#.....#..#.....##........##..# +#..##..#...##............#..##. +.#..##....#..........#..#.##.#. +..#####..#.#............##..... +...###.#....##..#.#....#.....#. +.#.......##....#...#.#.....##.. +...#....#...##.#...#..#........ +.####.....#....#.#.#...#....... +...#....#.....#.......#........ +#..#.#.......#...#............# +...#.....###.##....#.#.###.#... +.#.........#.......#.#....##... +#.#..#...#.#...##......#..#.... +.....#...#..#.#...#..###..#.... +......#.........#...###........ +.....#..##...#..........#.....# +..#..#.#.##.#...#....#....##..# +##....#.##...#.##.#..##....#... +.....#.#.#.#..#....##.#...#.#.. +.....##.......#........#....... +...#.#.....#...#...##.#......## +........#..#.#...#.#.....#.#..# +#..##...#.#...##..##...#.#...## +.##.#.#..#...#.....#.#.##.#...# +.#.####.........##.........#..# +.##..............#....#...#...# +......#...#..#...#..#..###.#... +.......##...#.#.#..##..#......# +.....#....#..##..#.........#... +.....#..#.#.#........#.#.####.. +#..#.......###....##........... +#..##..........#.#......#.#.... +.....##........#...#..##....... +###...#.##.#.#.#.#.##...##..... +....#...#........##.#.##..##... +.#..#.#.#......#.......##..#..# +.#...#.................#....#.. +.##..#..........#..##.......#.. +.#.#.#.....#..#.#.........##..# +...#......##...#.......#...##.. +##...###....#.###.............# +#.....#.#..#.#..#........#.#.#. +.....#.#......##..#.#.....#.##. +.......#...........#..#.......# +..#....#.#.#......#.....#...#.. +.....##........#..##..#..##.... +#.#........#...##....#.#..##... +#......#......#....#..#...#.##. +....#.#.......#.#.#............ +......####.#.##...#.#.##.....## +..###.#.#..#.........#.####.... +.#.......#..#.#....#.#..#.#.##. +#....#....#............##...##. +....#....#............#....#..# +..#........#..#....#..#..#...#. +.#......##....#..........#....# +#.##.....#..........#.###.#.... +....##...#.....#.#......#.##... +#.#.....#.......###.###..#..#.# +..###..##.............#.####.## +#....#.....#....#..##.......#.. +.....#....#...#.#.#.#..#...#.## +...#.....#..#....###......#.#.# +##.........#.#..#..#.#..#.....# +.#.....#.#....#.........##..#.# +.#.#..#.###..#..#..........#... +.##....#.#.#...#......##.....#. +#.#....#....#...#...##...#..#.. +#...#........#....#....#......# +#......#...#..#.#.##.....##..#. +....#...#......##...#..#....#.. +.#......##.##.......#.......#.. +.#...#..####...........#.#.#... +.........#...#.#.........#..... +#.##.....#.#..#.#.###...###..#. +#...##.###......#.###..##.#.##. +...##.#.....#....#..#......#... +#....###.#..#...##.....#......# +........###...#...#............ +........#....#...#...#....#...# +#....#..#..#....#.#........#.#. +##...#.....#.#..........#..#..# +#.#...##.....#........#...#...# +##.#.#.......#...#..#.###....#. +.#.......#....##..##...#.....#. +#....#....#.....#.......#...... +.##.##.##...##...#.#.#..#..#... +#..#..#.##....#......##....###. +.......#.#.........#..##.#...## +.#..##...#....#.....#.......... +..#.#...#......#.#..#.......... +.##....#.#.#.##.......###...#.. +..##.#...#.#.#.#.......#..#.... +#..#.......#...#........#.....# +.....#.......#......###..#..... +...##.#.......#.....##.....##.. +##..#.......#.#.....#....#..... +..#....#.##.##...#...#......#.. +.#..#.###.#....###........#...# +....##.##...##..#..#.#....#.... +..###...##.....##.............. +#....#...##...#....#..........# +.##........#......##...##...#.# +..#.#.##..........#......#..... +...#...#.........#.##........## +..#.#..#.#..#...#....#...#..... +...##...#..#.###.#..#.#...#.... +....###........#..#..##...#.... +#.#....##.......#.#........#... +.###...#..#.#.#.#..#...#..##.## +..#.........#####.#......#..#.. +#.....#.....##..#....#...#...#. +...#..#....##....##.....##.#... +.........#............#.##..... +....##.#..#....#.##.......#..## +.###....#.#..#......#.#.......# +.###...###.#.........#.#..#...# +.....#........#..#.#..#.#..##.# +.###..#....##.........#..##.... +..#.......#..#..##...#.###.#... +#.......#...........#.#...#.### +#.##.##...##.#...##..#.....#... +..#..#........###.#.....##..... +#.....##....#...##...####..#..# +....#........#...#...#......... +......#.#.#.#.......#..#.....## +..#..#....#.....#.#...##......# +..#....#...#.###.........#.###. +...#......##..#.#.....#...#.... +...#.......#...#...#........##. +............#...#..#....#.....# +....##......................#.. +#.#.#....#....#..........##.... +#.#.....#.#.##..#...#.##....##. +...#...#..#...#..#.#.#.......#. +#.....#..........#.........##.# +#...##..#..#.#.......###....#.. +.#...#..##....#.....##.......#. +....#.##.....#.........#.#....# +........#.#...####..#.......#.# +.####...#.#......####.....#.##. +###..#....#..#.......#.#..##..# +#......#.#....##..#.##.#....#.# +...###...#...#..##.#..#..#.#... +...##..##....#..#.....#........ +.....#..............#......#..# +......#....#......#..#......... +#..#.....#.##...........##..... +.#..#.#..................##.... +#.#..#..##...#....#.#......#... +.##.#.##......#.##...#...#...#. +..#...#.........#.#..#.#....#.. +.#.####.#..#.#......##.#..#.... +#..#.......#....#.............. +....#............#..#.......... +.....#####.....#.....#..##...## +#.#....#.#...............#..##. +.#.#..#...#......#.....#.#.#... +.#....#.#.#......#.....##....#. +....#....#.##..#.......###...## +.....#..#.##...#...#...#..#.#.. +##..#........#.#..#..##......#. +.#..#..##.......#..#.....#..... +.#.#.....###..##.#.#........... +..##..##.####..........#..#.... +..##..#..#...#....#......#.#... +#...#.#......##.....##.#..###.. +#..#..............#........##.# +.........#.##..#.#..#..##.##.#. +#....##....#.#..#.#...##..#.... +.#....#.......#............##.. +.......#.#.......#...#.#......# +......##...#.......#.#........# +..###..#.#.##....##...#....##.. +..##.##..........##..###....... +.#.#.#..#..#.#.......#.#...##.. +..#..##.........#.###..#......# +....#.#.#...##.#...#...##..###. +..###..##.........##...#...#..# +.#..##...#.......#.......#..#.# +........##....##....#.#.###.#.# +#.....#.#.................#.#.. +....#.#.#.....##.####.#......#. +....#.......#.#.##.##.......... +...#...........#...#.##...#.### +#....#....#..........#.##...... +##..#...........##.....##.##... +.#.##...##..##....#..#.....#### +#...#...#.##..........##..##... +....##..#....#.....#.#...#....# +..#....#..##...###.#.#......... +#......#.#.#...#...#.........#. +#............###.#.#.#..##...#. +.##.....####...##..##..#..##.#. +#..#........#.....#.#.....#...# +#............#....#.#.#........ +......##...##.#....#.....#...#. +..#........##......#.#.....##.. +.#..#..#.....##.......#..#.#..# +.#....#..#....##.#.#.#..#..#.## +.####.#..........#...#..##..... +...###..###...##..#............ +#..#.....##.#...#..##..#....... +.....##....#...###.##...#...... +...##..#...#..#..##....##....#. +...###....#.###.#.#.##....#.... +##.#.#.....#....#.#....#..#.... +.......##.....#.#..##...##...#. +.#....#.#...##.#..#....#.....#. +..#...#..#...#.##........#...#. +#....#......##.#....##...#.#..# +.....#..#..#..#......#...#.#.#. +..###....#........#...#.......# +###...#.......#.#.......##.##.. +......##.....#.#........#....#. +#.##..#.#.#.#..#....#.##.....#. +..........#.##.#...#...#..#..#. +..#...##.#..........#..##.###.. +..###..##.##..#.#...##.####..#. +#.#.#...............##....###.# +....#.........#.#....#.#....#.# +..#...#.###...#....###.....#... +..#..#....#...#............#... +.#..#....#..##.....##.......... +..#....#.#...#.#.#.#.......##.# +.........#....##........#.#.... +...#..##.#..#.##...#...#.#....# +....####...#...####.#....###..# +......##...#.##.#.......#..#... +#.#...#.#...#.#...#....#.#.#... +.#.....##...#.....###.#....#... +......##.....###...#.#...#.#... +#..#..##.#.#......#....#..#..#. +....#.###.....#..#...#.##.....# +##.##........#......#....#..##. +##.....##.#.....#.....##.....#. +.....#.##...#.#..#.#.#.....#... +.#.##..#...#.#..#.....#.#...... +.....##.......#..#...##..#..#.. +#.....#..#.####......#........# +.#..#..##.#..##............#..# +.##..#.#....##.##.....#......#. +.......##.........#..#......... +.#...#.......................#. +#......#.#....##.#.......#..#.. +..##..##......#.......#....#.#. +##......#......##...##......... +..#....####....#.#.....##.#.#.. +..........#..#.#.#.....#..#.#.. +##..##...........##.......#.... +##....#.#....#..#......###....# +...#.#.#..#.......##.......#... +#....#.......#.......#......... +...##......##....#...#......#.# +#......#####.#.........#.....#. +#..#.............#..#....#...#. +.......#.##..#..#..#..#....#### +......#.##..##..........###...# +.#.##....###..#........#....##. +#......#..#...###.#...#.....#.. +.#.#.......#....##.......#.#... +..#.##..#..##.....#.........#.# +#.#...#..#.##....#.......##.... +.#.....###....#.#..#...#.....#. +#...#..#.......#.#.....##...#.# +#.#####.........#....##.....#.. +#....#..##...#....#.##.......#. +.#.#.........##....##....#..... +...#..##.......#....#.#.#...... +#.###.##...###....#.....#.####. +.#...#.#.#..##.#..........#.... +#.#.....#.##.#..####.....##.#.. +...###.##..####.......#......## +.##..#.........#...#.#.....#.## +..#.....##....###.....#.#...##. +#....#....#..#....#.##......... +......###....#.#..#..#....##... +.#.#................#.......##. +...#.......#.........#.#....... +...#..........#...##.....###... +....#......#...#............... +.##...#....#.....#.##......#... +.#.....###...##..##...#.#...... +....##........#.....#...#....#. +#.........#.#...##...#.#..#.... +...#.#.....#.#........#.#....#. +.#........#.....#.#.#.#.#..#... +....#...#.....#.#....#........# +..###.#....#.#....##...##..#.## +.#....#.#.####.#.#.....#....... +.#...#...#.................##.# +..................##..#..#.#.#. +.#..#............##....###..... +.......#....#...........#...... +....#.#.#.....###.........#..## +...#.#....#.#.##.#.##.....##..# +.#.##.#...##...#.......#.....## +.#............#...#..##...#.#.# +#.##..#.##..#..##.###.#........ +..............##....#...#..#.#. +.#.#...#.#....#....###........# +.#....#.#....#......###........ +..#.......##......#.##.....#... +.....#......#..#...#.#.....#... \ No newline at end of file -- cgit v1.2.3