diff options
| author | 2020-12-12 03:07:25 +0100 | |
|---|---|---|
| committer | 2020-12-12 03:07:25 +0100 | |
| commit | 35536a73389e9d555e42f9388552b7c43f5c3a8b (patch) | |
| tree | df98e8043543fdffdb767128b7a5d97b998a1b27 /day3 | |
| parent | 4985ee94450df0bbcf982b7652c946a47707e60c (diff) | |
| download | 2021-35536a73389e9d555e42f9388552b7c43f5c3a8b.tar.gz 2021-35536a73389e9d555e42f9388552b7c43f5c3a8b.tar.bz2 2021-35536a73389e9d555e42f9388552b7c43f5c3a8b.zip | |
Added day 3
Diffstat (limited to 'day3')
| -rw-r--r-- | day3/__init__.py | 43 | ||||
| -rw-r--r-- | day3/example.txt | 11 | ||||
| -rw-r--r-- | day3/input.txt | 323 |
3 files changed, 377 insertions, 0 deletions
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 @@ | |||
| 1 | from functools import reduce | ||
| 2 | from typing import List, Generator | ||
| 3 | |||
| 4 | from aoc import BaseAssignment | ||
| 5 | |||
| 6 | |||
| 7 | class 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 | |||
| 30 | class AssignmentOne(Assignment): | ||
| 31 | def run(self, input: List): | ||
| 32 | return self.get_trees_for_slope(input, 3, 1) | ||
| 33 | |||
| 34 | class 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 | |||
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 @@ | |||
| 1 | ..##....... | ||
| 2 | #...#...#.. | ||
| 3 | .#....#..#. | ||
| 4 | ..#.#...#.# | ||
| 5 | .#...##..#. | ||
| 6 | ..#.##..... | ||
| 7 | .#.#.#....# | ||
| 8 | .#........# | ||
| 9 | #.##...#... | ||
| 10 | #...##....# | ||
| 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 @@ | |||
| 1 | ...#...#....#....##...###....#. | ||
| 2 | #.#...#...#....#.........#..#.. | ||
| 3 | .#....##..#.#..##..##.......... | ||
| 4 | .....#.#.............#..#...... | ||
| 5 | .......#...#.##.#......#..#.#.. | ||
| 6 | #.#....#......##........##..... | ||
| 7 | .....##.#....#..#...#...##...#. | ||
| 8 | ...#...#..#.......#..#...##...# | ||
| 9 | ..........#...........##....... | ||
| 10 | ..#..#..#...................#.. | ||
| 11 | #..#....#.....##.#.#..........# | ||
| 12 | .#.##.......###.....#.#...#.... | ||
| 13 | .#..##....##....#.......#...### | ||
| 14 | #.#..##...#.#..#............... | ||
| 15 | .........#....#.......##.#.#... | ||
| 16 | ...###...##....##...#..##.#..#. | ||
| 17 | ....#.........#..#...#.......#. | ||
| 18 | ....................#..#.#.#... | ||
| 19 | ..#....#..........#...........# | ||
| 20 | .#.....#..#.....##........##..# | ||
| 21 | #..##..#...##............#..##. | ||
| 22 | .#..##....#..........#..#.##.#. | ||
| 23 | ..#####..#.#............##..... | ||
| 24 | ...###.#....##..#.#....#.....#. | ||
| 25 | .#.......##....#...#.#.....##.. | ||
| 26 | ...#....#...##.#...#..#........ | ||
| 27 | .####.....#....#.#.#...#....... | ||
| 28 | ...#....#.....#.......#........ | ||
| 29 | #..#.#.......#...#............# | ||
| 30 | ...#.....###.##....#.#.###.#... | ||
| 31 | .#.........#.......#.#....##... | ||
| 32 | #.#..#...#.#...##......#..#.... | ||
| 33 | .....#...#..#.#...#..###..#.... | ||
| 34 | ......#.........#...###........ | ||
| 35 | .....#..##...#..........#.....# | ||
| 36 | ..#..#.#.##.#...#....#....##..# | ||
| 37 | ##....#.##...#.##.#..##....#... | ||
| 38 | .....#.#.#.#..#....##.#...#.#.. | ||
| 39 | .....##.......#........#....... | ||
| 40 | ...#.#.....#...#...##.#......## | ||
| 41 | ........#..#.#...#.#.....#.#..# | ||
| 42 | #..##...#.#...##..##...#.#...## | ||
| 43 | .##.#.#..#...#.....#.#.##.#...# | ||
| 44 | .#.####.........##.........#..# | ||
| 45 | .##..............#....#...#...# | ||
| 46 | ......#...#..#...#..#..###.#... | ||
| 47 | .......##...#.#.#..##..#......# | ||
| 48 | .....#....#..##..#.........#... | ||
| 49 | .....#..#.#.#........#.#.####.. | ||
| 50 | #..#.......###....##........... | ||
| 51 | #..##..........#.#......#.#.... | ||
| 52 | .....##........#...#..##....... | ||
| 53 | ###...#.##.#.#.#.#.##...##..... | ||
| 54 | ....#...#........##.#.##..##... | ||
| 55 | .#..#.#.#......#.......##..#..# | ||
| 56 | .#...#.................#....#.. | ||
| 57 | .##..#..........#..##.......#.. | ||
| 58 | .#.#.#.....#..#.#.........##..# | ||
| 59 | ...#......##...#.......#...##.. | ||
| 60 | ##...###....#.###.............# | ||
| 61 | #.....#.#..#.#..#........#.#.#. | ||
| 62 | .....#.#......##..#.#.....#.##. | ||
| 63 | .......#...........#..#.......# | ||
| 64 | ..#....#.#.#......#.....#...#.. | ||
| 65 | .....##........#..##..#..##.... | ||
| 66 | #.#........#...##....#.#..##... | ||
| 67 | #......#......#....#..#...#.##. | ||
| 68 | ....#.#.......#.#.#............ | ||
| 69 | ......####.#.##...#.#.##.....## | ||
| 70 | ..###.#.#..#.........#.####.... | ||
| 71 | .#.......#..#.#....#.#..#.#.##. | ||
| 72 | #....#....#............##...##. | ||
| 73 | ....#....#............#....#..# | ||
| 74 | ..#........#..#....#..#..#...#. | ||
| 75 | .#......##....#..........#....# | ||
| 76 | #.##.....#..........#.###.#.... | ||
| 77 | ....##...#.....#.#......#.##... | ||
| 78 | #.#.....#.......###.###..#..#.# | ||
| 79 | ..###..##.............#.####.## | ||
| 80 | #....#.....#....#..##.......#.. | ||
| 81 | .....#....#...#.#.#.#..#...#.## | ||
| 82 | ...#.....#..#....###......#.#.# | ||
| 83 | ##.........#.#..#..#.#..#.....# | ||
| 84 | .#.....#.#....#.........##..#.# | ||
| 85 | .#.#..#.###..#..#..........#... | ||
| 86 | .##....#.#.#...#......##.....#. | ||
| 87 | #.#....#....#...#...##...#..#.. | ||
| 88 | #...#........#....#....#......# | ||
| 89 | #......#...#..#.#.##.....##..#. | ||
| 90 | ....#...#......##...#..#....#.. | ||
| 91 | .#......##.##.......#.......#.. | ||
| 92 | .#...#..####...........#.#.#... | ||
| 93 | .........#...#.#.........#..... | ||
| 94 | #.##.....#.#..#.#.###...###..#. | ||
| 95 | #...##.###......#.###..##.#.##. | ||
| 96 | ...##.#.....#....#..#......#... | ||
| 97 | #....###.#..#...##.....#......# | ||
| 98 | ........###...#...#............ | ||
| 99 | ........#....#...#...#....#...# | ||
| 100 | #....#..#..#....#.#........#.#. | ||
| 101 | ##...#.....#.#..........#..#..# | ||
| 102 | #.#...##.....#........#...#...# | ||
| 103 | ##.#.#.......#...#..#.###....#. | ||
| 104 | .#.......#....##..##...#.....#. | ||
| 105 | #....#....#.....#.......#...... | ||
| 106 | .##.##.##...##...#.#.#..#..#... | ||
| 107 | #..#..#.##....#......##....###. | ||
| 108 | .......#.#.........#..##.#...## | ||
| 109 | .#..##...#....#.....#.......... | ||
| 110 | ..#.#...#......#.#..#.......... | ||
| 111 | .##....#.#.#.##.......###...#.. | ||
| 112 | ..##.#...#.#.#.#.......#..#.... | ||
| 113 | #..#.......#...#........#.....# | ||
| 114 | .....#.......#......###..#..... | ||
| 115 | ...##.#.......#.....##.....##.. | ||
| 116 | ##..#.......#.#.....#....#..... | ||
| 117 | ..#....#.##.##...#...#......#.. | ||
| 118 | .#..#.###.#....###........#...# | ||
| 119 | ....##.##...##..#..#.#....#.... | ||
| 120 | ..###...##.....##.............. | ||
| 121 | #....#...##...#....#..........# | ||
| 122 | .##........#......##...##...#.# | ||
| 123 | ..#.#.##..........#......#..... | ||
| 124 | ...#...#.........#.##........## | ||
| 125 | ..#.#..#.#..#...#....#...#..... | ||
| 126 | ...##...#..#.###.#..#.#...#.... | ||
| 127 | ....###........#..#..##...#.... | ||
| 128 | #.#....##.......#.#........#... | ||
| 129 | .###...#..#.#.#.#..#...#..##.## | ||
| 130 | ..#.........#####.#......#..#.. | ||
| 131 | #.....#.....##..#....#...#...#. | ||
| 132 | ...#..#....##....##.....##.#... | ||
| 133 | .........#............#.##..... | ||
| 134 | ....##.#..#....#.##.......#..## | ||
| 135 | .###....#.#..#......#.#.......# | ||
| 136 | .###...###.#.........#.#..#...# | ||
| 137 | .....#........#..#.#..#.#..##.# | ||
| 138 | .###..#....##.........#..##.... | ||
| 139 | ..#.......#..#..##...#.###.#... | ||
| 140 | #.......#...........#.#...#.### | ||
| 141 | #.##.##...##.#...##..#.....#... | ||
| 142 | ..#..#........###.#.....##..... | ||
| 143 | #.....##....#...##...####..#..# | ||
| 144 | ....#........#...#...#......... | ||
| 145 | ......#.#.#.#.......#..#.....## | ||
| 146 | ..#..#....#.....#.#...##......# | ||
| 147 | ..#....#...#.###.........#.###. | ||
| 148 | ...#......##..#.#.....#...#.... | ||
| 149 | ...#.......#...#...#........##. | ||
| 150 | ............#...#..#....#.....# | ||
| 151 | ....##......................#.. | ||
| 152 | #.#.#....#....#..........##.... | ||
| 153 | #.#.....#.#.##..#...#.##....##. | ||
| 154 | ...#...#..#...#..#.#.#.......#. | ||
| 155 | #.....#..........#.........##.# | ||
| 156 | #...##..#..#.#.......###....#.. | ||
| 157 | .#...#..##....#.....##.......#. | ||
| 158 | ....#.##.....#.........#.#....# | ||
| 159 | ........#.#...####..#.......#.# | ||
| 160 | .####...#.#......####.....#.##. | ||
| 161 | ###..#....#..#.......#.#..##..# | ||
| 162 | #......#.#....##..#.##.#....#.# | ||
| 163 | ...###...#...#..##.#..#..#.#... | ||
| 164 | ...##..##....#..#.....#........ | ||
| 165 | .....#..............#......#..# | ||
| 166 | ......#....#......#..#......... | ||
| 167 | #..#.....#.##...........##..... | ||
| 168 | .#..#.#..................##.... | ||
| 169 | #.#..#..##...#....#.#......#... | ||
| 170 | .##.#.##......#.##...#...#...#. | ||
| 171 | ..#...#.........#.#..#.#....#.. | ||
| 172 | .#.####.#..#.#......##.#..#.... | ||
| 173 | #..#.......#....#.............. | ||
| 174 | ....#............#..#.......... | ||
| 175 | .....#####.....#.....#..##...## | ||
| 176 | #.#....#.#...............#..##. | ||
| 177 | .#.#..#...#......#.....#.#.#... | ||
| 178 | .#....#.#.#......#.....##....#. | ||
| 179 | ....#....#.##..#.......###...## | ||
| 180 | .....#..#.##...#...#...#..#. | ||
