diff --git a/03/03.py b/03/03.py new file mode 100644 index 0000000..d76b8b7 --- /dev/null +++ b/03/03.py @@ -0,0 +1,38 @@ +def read_file(): + with open("input.txt","r") as f: + return f.read().split('\n') + +def part1(tree_map): + width = len(tree_map[0]) + trees_encountered = 0 + for i, line in enumerate(tree_map): + if tree_map[i][3*i % width] == "#": + trees_encountered += 1 + return trees_encountered + +def part2(tree_map, right, down): + height = len(tree_map) + width = len(tree_map[0]) + trees_encountered = 0 + i = 0 + j = 0 + while i < height: + if tree_map[i][(j % width)] == "#": + trees_encountered += 1 + i += down + j += right + return trees_encountered + +def main(): + tree_map = read_file() + print(f'Part 1: {part1(tree_map)}') + a = part2(tree_map, 1, 1) + b = part2(tree_map, 3, 1) + assert b == part1(tree_map) + c = part2(tree_map, 5, 1) + d = part2(tree_map, 7, 1) + e = part2(tree_map, 1, 2) + print(f'Part 2: {a*b*c*d*e}') + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/03/input.txt b/03/input.txt new file mode 100644 index 0000000..90141e9 --- /dev/null +++ b/03/input.txt @@ -0,0 +1,323 @@ +....#..#.......#........#....#. +..##.#.#.#...................#. +....#.#.##..#....#......#...... +.........#.#......##.....#..... +..........#.###.##...##........ +#....#.#.......##.....#..#..... +#...........#.#...#..#..##.##.. +......##.............#.....#... +..##..........###..#.#..##..... +...........#........#......##.. +..##...........##.............. +..#......###.#.....#.#.#....... +..#..#..#..........#.#....#.... +.#.....##...................... +...#...##..#...#.........#..##. +.#......#..#..#...#......#.##.. +..##.##.......#..#.....#..#...# +..............#..#..#...#...... +...#...#....##.....#...#...#... +......................#...#.... +.......#......#...#..##...#.#.. +##......#..#.....#....#.....#.. +....#.#.##.#.#....#............ +#.....##.............#......... +..........#...........#.#.....# +...#...##....#.#........#..#... +................#..#.##.##....# +......#...#...##...##....#..... +##....#..#..#...#..#........... +#..................#...#.#..#.. +....##....##.#....#..#......#.. +.....#...........#.........##.. +..#..............#.........#..# +......##....................#.. +..#.....###...####...#...#.##.. +#..#.#......#.....#.......#.#.. +##.#.........######........#... +..#....###...#.#..............# +.....#..............#.........# +....#......#..#.........#...#.. +.....###.....#.###.......###... +#.#..#.....#....##...#........# +..##....#..#.........#...#.#... +..#..##.............#....#.#.#. +..##.#..#.#.#.........##....... +#.#..#.........#..............# +#..#.........###.......#.#..#.# +.............#...#....#......#. +..........#.#...##.###.....#.#. +..#.....#...................... +.......#......###.#.......#.... +....#....#.........#...###.#.#. +.#.............#............#.. +....#..#.............#.#....#.. +....#.....#...#...##.#......... +..#...#...#..................#. +........#....#.....#........... +.....##.......#...#.#..#..#.... +...#............#..#.#......... +......................#........ +....#......#.....#.#....#...... +.....#..#.........#.........##. +...............#.....#....##... +...#.#.#...#..#...........#.... +.#....###......##...#.#.#.#.... +.....#...#....####....##....... +..#......#..#.....##.#...#..... +...#.##..#....#..##.....#...... +..#......#...#...##.....#...#.. +......#.....#........#......... +..#.#....#..............##....# +..#...#......##............#... +.##.#.......#.......#......#..# +...##.##...#.....#.......#..#.. +......##..#....#.......#....... +.....#..#..#.#.....#.....#...## +##.#...#.#.#.....#...#.#.#.##.# +...................###...#..#.. +.#.....##.#......#........#.... +.##...##.#..........#...#....#. +......#..............#.#......# +...#.......#..#...........#.... +.###...#............##..#...##. +##..#.#.........#............#. +#...#.#......#.##...........#.# +.#.#...#........#......##...... +....#...#...#.....#...#....#... +...##...........##.........#... +.........#...#..###............ +..#........#...............#... +.............#....#.#.......... +........#......#.#.......#....# +.................#....##.#.##.. +..#...##........#.............. +#..#........#...#....#......... +......#.#.....#.....#..###.#..# +....#............#...#.#.#..... +............#..........#...#... +..........#....##.#.........#.. +..............#...#...#..#..... +#......#....#..##....#......##. +...#....#.................#.... +.#.##.............#...#....##.. +....#..#.........#..#....#....# +..#.....##..#......#.#..#...... +..#..#.....#........#...#..#..# +.........##.#.##.#.......#....# +..#.......##.##...#.....#.....# +.............##...#...........# +..#......#..#....#...#..#.##... +....#........#......#.........# +.......#........#..#.#.#..##..# +..#......#...........##...#.... +.....#..#.#...#..............## +.#..#......#......#........#..# +...##...............#....#..... +.......#...#.......##..#....... +.....#....#...#...#..#.....#.#. +...#.........#.....#........... +...#.....###....#....#...#...#. +#..#.....#.........#.........#. +.................#.#.....#....# +...........#..........#..#..... +........#.#....#...#..#.....### +#............................#. +..##..#..#...##.........#...... +......##....#.#...#.........#.. +......#..##.#......#..#.....#.. +...#.......##....#.#....#...... +.....#........#...#............ +#.......#...#.........#......#. +......#......#....#..#......... +..#.#........#..#......#....#.. +.#..#.#..........##....###.#..# +...#....#.##..#...#....#....... +..#.....#......#.###.......#... +..............................# +.....#..#...#...........#...... +.##...#....##....#.#.#.#....#.# +.#...#....#...#........#....... +....#............#...##..#..... +....##..#....#....#.....#....## +.............#..##.#.#.#....... +#.......#.#.#.......#..#..#.... +#..#...........#.......###..#.. +.#..##.#.....#........#........ +..#.#.......#............#..#.. +...........#..#............##.# +.....#.......#.....#..#.##.#..# +......#......##.....##......... +..##.#..#.#..#..#.............. +.....#.............##...#.#.##. +.#......##.#..........#........ +..#..#.........#.....#.#.#..... +..#.....#.......#.....#..#..... +#.#.#........#.#...#....#..#... +.#.#.......#............#....#. +......#..................#....# +.#...#...#.....#.#..........#.. +.#..##....####...........#.#... +..##.....#...#.#....#....#..... +#.....................#....#.#. +###..###.#.#...........#.....## +......#......#..........#...... +...#......#.##.....#......###.# +.............#..#.#...........# +..#.............#.#..#.....#... +...#...............#....##...## +........#.................#.... +#..###.....#.......##.#......## +....#.#..............#......... +#..........#.....#..##...#..... +................#...#..#....#.. +..#...#....##..........#.#..... +......#........##......#..#...# +...#....#..#.....#.......#...#. +.#.....#..#...#..###....#...... +....#.........#....#.#.#.....#. +#.#....#...#....#.....#..##.... +.......#..#..#..........#...#.. +..#.#..#.....##.#.#............ +..#....#.....#..##..#..#.#..#.. +..#.##.#...........#...#..#.... +.........#........#...#........ +..#.#.#.......##.........#.##.. +#.#..........#.#...#..#......## +.#..#....................#.#... +.##......#................#...# +..##.#######......#....#....... +....#...##.#....#.#............ +.##....#...##.......#...#..#... +...........#...#...#...#..#.... +#...#.....#.......#....#.....#. +.............#................. +........#.#.......#...#.#.#.... +..............#............#.#. +......#......##..#.......#....# +##...#..................#...... +.....#......###.....#.......#.# +.....#.#............#.#........ +..#.#..#............#....#.#... +##.#.###.#.#.#..#......#....... +...##........#..#.....#.#.#..#. +##......#.##.....####..#....... +............#...#..#...#..#.... +...#..#................##.#..#. +.#....#.#...........##.#.#...#. +####..#...........#.......###.. +.......#.................#..... +.......#....#.......##....#.... +..#.........#...#....#......... +..........#..#...#.#...##..#... +....##..........#.........##... +#.........##..#.#..#.......#... +.#...........#....#...#...#.#.. +....#..#.....#...##....#.#....# +.#....#.....#......#..##.##.#.# +#......#..#.......##........... +...#..#...#.#.................# +......#.......##....##.#......# +....#....#.#.#.....#....#....#. +..#..........#.##...##..#...... +...#..#........#....#.#..#....# +##.......#........#..........#. +.#........#.......#...#..##...# +..#..#..##..#...........#...### +..#......#..........#..##...... +.#.....#..#.#...#...#.........# +#.#......##.................... +#...#.....##...........#....... +........#...#....#.......##.... +...#.##...#....#....#..#..#..#. +...#..#......##....#..#..##.... +#...#..........#.#............. +##..#........##.....#.........# +.....#......#.#...###..#....... +#..##.#..#.###...........##..#. +.....#....#..........#.......#. +##.........##.#................ +....#.........#............##.. +.......#........#......#..#..## +.#...#...##..#....#..#......... +.............#...#.#........#.. +......#..#...#..#.###..#....... +........##.#..#.#..#..#........ +#.##..#..#..........#...##..### +.##...#............#.#...##..#. +................#....##.#...#.. +#.................#..........#. +...#..#..#..................... +..#...##.#.#................... +.....#...#.......#............# +..#..#.........#..##.#..#.#...# +.....#.#.....#.#.......#.....#. +..................#..#....#.#.. +..#.....###.##.......##....#.#. +..#......##.......#....##.#.... +....#...................#..##.# +.......#....#.##.#.......#....# +..#...#......#..#...###....#.#. +..#..#.#....#...........#.....# +.....#..#..#.......#........#.. +......#.##.#......#...........# +#...#....#.#..##.##..#..##..... +#...##....#.#...##........#.... +..##............#.#.#.......... +....#.....#.#..#.......#..#.... +#..#.#.....#..#..##...#..##.... +...##........#...........#...#. +.####......#..##.........#.#... +.......#....................... +.................#....#..#..... +.........##......###........... +.##......#.#.#....#.#...#..###. +....#......##.###.#.#..#....... +..........#.......##......##..# +...........#.......#..##....... +.....###..#..............##.... +........##..#.#.#......#....#.. +#....#......................... +...........#...............##.. +......#.................#...... +.....#...#..##...##...#...#.... +..........#.#...##.####......#. +..#.#.....##....#...........#.. +..........#....#..#....##...#.. +.#.......#..##...#...#.....#... +...##....#.#......##...##....#. +#.......#.......#.##.#...#.#... +#...#..................#......# +..#.......#...............#..## +#.....#..................#....# +.##.....#.....#......####.....# +..#........#...#.#........#...# +..##.....#....#...#...........# +..#..#.....##..#.##...#........ +..........###..#....##.....#... +...#...#....#.##.#...#.#....... +..##......#.......#.......##... +............#............#..... +.##....#.........#............. +....#....#....#........##...#.# +.......##...................... +..........#.#.................# +......##.#...#.........#.....#. +..#...#......#..#.............# +..........###.#..#.#...#..#..#. +#..#.#..#....##...#...#.#...#.. +.#........##...#......#.##..... +...###.#...##..............##.. +#.#.#...#...#..#....#.#..#..... +.#.#.##..#....#......#.#....... +...#..#.#....##...........#..#. +.....##..##......#.#........... +......#.....#....####....#..... +.#.#.#...#..#..#...........#... +.....#......................#.. +.........#.........#.###.##.... +.....#......##..........#...... +..#...........##...........#... +..............#.........#.....# +..#....#..#...#...##.#......... +.#.#.#....#..........#......... \ No newline at end of file