This commit is contained in:
a 2020-12-03 14:41:28 -06:00
parent afe06c8955
commit 3f4ade67a3
2 changed files with 361 additions and 0 deletions

38
03/03.py Normal file
View file

@ -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()

323
03/input.txt Normal file
View file

@ -0,0 +1,323 @@
....#..#.......#........#....#.
..##.#.#.#...................#.
....#.#.##..#....#......#......
.........#.#......##.....#.....
..........#.###.##...##........
#....#.#.......##.....#..#.....
#...........#.#...#..#..##.##..
......##.............#.....#...
..##..........###..#.#..##.....
...........#........#......##..
..##...........##..............
..#......###.#.....#.#.#.......
..#..#..#..........#.#....#....
.#.....##......................
...#...##..#...#.........#..##.
.#......#..#..#...#......#.##..
..##.##.......#..#.....#..#...#
..............#..#..#...#......
...#...#....##.....#...#...#...
......................#...#....
.......#......#...#..##...#.#..
##......#..#.....#....#.....#..
....#.#.##.#.#....#............
#.....##.............#.........
..........#...........#.#.....#
...#...##....#.#........#..#...
................#..#.##.##....#
......#...#...##...##....#.....
##....#..#..#...#..#...........
#..................#...#.#..#..
....##....##.#....#..#......#..
.....#...........#.........##..
..#..............#.........#..#
......##....................#..
..#.....###...####...#...#.##..
#..#.#......#.....#.......#.#..
##.#.........######........#...
..#....###...#.#..............#
.....#..............#.........#
....#......#..#.........#...#..
.....###.....#.###.......###...
#.#..#.....#....##...#........#
..##....#..#.........#...#.#...
..#..##.............#....#.#.#.
..##.#..#.#.#.........##.......
#.#..#.........#..............#
#..#.........###.......#.#..#.#
.............#...#....#......#.
..........#.#...##.###.....#.#.
..#.....#......................
.......#......###.#.......#....
....#....#.........#...###.#.#.
.#.............#............#..
....#..#.............#.#....#..
....#.....#...#...##.#.........
..#...#...#..................#.
........#....#.....#...........
.....##.......#...#.#..#..#....
...#............#..#.#.........
......................#........
....#......#.....#.#....#......
.....#..#.........#.........##.
...............#.....#....##...
...#.#.#...#..#...........#....
.#....###......##...#.#.#.#....
.....#...#....####....##.......
..#......#..#.....##.#...#.....
...#.##..#....#..##.....#......
..#......#...#...##.....#...#..
......#.....#........#.........
..#.#....#..............##....#
..#...#......##............#...
.##.#.......#.......#......#..#
...##.##...#.....#.......#..#..
......##..#....#.......#.......
.....#..#..#.#.....#.....#...##
##.#...#.#.#.....#...#.#.#.##.#
...................###...#..#..
.#.....##.#......#........#....
.##...##.#..........#...#....#.
......#..............#.#......#
...#.......#..#...........#....
.###...#............##..#...##.
##..#.#.........#............#.
#...#.#......#.##...........#.#
.#.#...#........#......##......
....#...#...#.....#...#....#...
...##...........##.........#...
.........#...#..###............
..#........#...............#...
.............#....#.#..........
........#......#.#.......#....#
.................#....##.#.##..
..#...##........#..............
#..#........#...#....#.........
......#.#.....#.....#..###.#..#
....#............#...#.#.#.....
............#..........#...#...
..........#....##.#.........#..
..............#...#...#..#.....
#......#....#..##....#......##.
...#....#.................#....
.#.##.............#...#....##..
....#..#.........#..#....#....#
..#.....##..#......#.#..#......
..#..#.....#........#...#..#..#
.........##.#.##.#.......#....#
..#.......##.##...#.....#.....#
.............##...#...........#
..#......#..#....#...#..#.##...
....#........#......#.........#
.......#........#..#.#.#..##..#
..#......#...........##...#....
.....#..#.#...#..............##
.#..#......#......#........#..#
...##...............#....#.....
.......#...#.......##..#.......
.....#....#...#...#..#.....#.#.
...#.........#.....#...........
...#.....###....#....#...#...#.
#..#.....#.........#.........#.
.................#.#.....#....#
...........#..........#..#.....
........#.#....#...#..#.....###
#............................#.
..##..#..#...##.........#......
......##....#.#...#.........#..
......#..##.#......#..#.....#..
...#.......##....#.#....#......
.....#........#...#............
#.......#...#.........#......#.
......#......#....#..#.........
..#.#........#..#......#....#..
.#..#.#..........##....###.#..#
...#....#.##..#...#....#.......
..#.....#......#.###.......#...
..............................#
.....#..#...#...........#......
.##...#....##....#.#.#.#....#.#
.#...#....#...#........#.......
....#............#...##..#.....
....##..#....#....#.....#....##
.............#..##.#.#.#.......
#.......#.#.#.......#..#..#....
#..#...........#.......###..#..
.#..##.#.....#........#........
..#.#.......#............#..#..
...........#..#............##.#
.....#.......#.....#..#.##.#..#
......#......##.....##.........
..##.#..#.#..#..#..............
.....#.............##...#.#.##.
.#......##.#..........#........
..#..#.........#.....#.#.#.....
..#.....#.......#.....#..#.....
#.#.#........#.#...#....#..#...
.#.#.......#............#....#.
......#..................#....#
.#...#...#.....#.#..........#..
.#..##....####...........#.#...
..##.....#...#.#....#....#.....
#.....................#....#.#.
###..###.#.#...........#.....##
......#......#..........#......
...#......#.##.....#......###.#
.............#..#.#...........#
..#.............#.#..#.....#...
...#...............#....##...##
........#.................#....
#..###.....#.......##.#......##
....#.#..............#.........
#..........#.....#..##...#.....
................#...#..#....#..
..#...#....##..........#.#.....
......#........##......#..#...#
...#....#..#.....#.......#...#.
.#.....#..#...#..###....#......
....#.........#....#.#.#.....#.
#.#....#...#....#.....#..##....
.......#..#..#..........#...#..
..#.#..#.....##.#.#............
..#....#.....#..##..#..#.#..#..
..#.##.#...........#...#..#....
.........#........#...#........
..#.#.#.......##.........#.##..
#.#..........#.#...#..#......##
.#..#....................#.#...
.##......#................#...#
..##.#######......#....#.......
....#...##.#....#.#............
.##....#...##.......#...#..#...
...........#...#...#...#..#....
#...#.....#.......#....#.....#.
.............#.................
........#.#.......#...#.#.#....
..............#............#.#.
......#......##..#.......#....#
##...#..................#......
.....#......###.....#.......#.#
.....#.#............#.#........
..#.#..#............#....#.#...
##.#.###.#.#.#..#......#.......
...##........#..#.....#.#.#..#.
##......#.##.....####..#.......
............#...#..#...#..#....
...#..#................##.#..#.
.#....#.#...........##.#.#...#.
####..#...........#.......###..
.......#.................#.....
.......#....#.......##....#....
..#.........#...#....#.........
..........#..#...#.#...##..#...
....##..........#.........##...
#.........##..#.#..#.......#...
.#...........#....#...#...#.#..
....#..#.....#...##....#.#....#
.#....#.....#......#..##.##.#.#
#......#..#.......##...........
...#..#...#.#.................#
......#.......##....##.#......#
....#....#.#.#.....#....#....#.
..#..........#.##...##..#......
...#..#........#....#.#..#....#
##.......#........#..........#.
.#........#.......#...#..##...#
..#..#..##..#...........#...###
..#......#..........#..##......
.#.....#..#.#...#...#.........#
#.#......##....................
#...#.....##...........#.......
........#...#....#.......##....
...#.##...#....#....#..#..#..#.
...#..#......##....#..#..##....
#...#..........#.#.............
##..#........##.....#.........#
.....#......#.#...###..#.......
#..##.#..#.###...........##..#.
.....#....#..........#.......#.
##.........##.#................
....#.........#............##..
.......#........#......#..#..##
.#...#...##..#....#..#.........
.............#...#.#........#..
......#..#...#..#.###..#.......
........##.#..#.#..#..#........
#.##..#..#..........#...##..###
.##...#............#.#...##..#.
................#....##.#...#..
#.................#..........#.
...#..#..#.....................
..#...##.#.#...................
.....#...#.......#............#
..#..#.........#..##.#..#.#...#
.....#.#.....#.#.......#.....#.
..................#..#....#.#..
..#.....###.##.......##....#.#.
..#......##.......#....##.#....
....#...................#..##.#
.......#....#.##.#.......#....#
..#...#......#..#...###....#.#.
..#..#.#....#...........#.....#
.....#..#..#.......#........#..
......#.##.#......#...........#
#...#....#.#..##.##..#..##.....
#...##....#.#...##........#....
..##............#.#.#..........
....#.....#.#..#.......#..#....
#..#.#.....#..#..##...#..##....
...##........#...........#...#.
.####......#..##.........#.#...
.......#.......................
.................#....#..#.....
.........##......###...........
.##......#.#.#....#.#...#..###.
....#......##.###.#.#..#.......
..........#.......##......##..#
...........#.......#..##.......
.....###..#..............##....
........##..#.#.#......#....#..
#....#.........................
...........#...............##..
......#.................#......
.....#...#..##...##...#...#....
..........#.#...##.####......#.
..#.#.....##....#...........#..
..........#....#..#....##...#..
.#.......#..##...#...#.....#...
...##....#.#......##...##....#.
#.......#.......#.##.#...#.#...
#...#..................#......#
..#.......#...............#..##
#.....#..................#....#
.##.....#.....#......####.....#
..#........#...#.#........#...#
..##.....#....#...#...........#
..#..#.....##..#.##...#........
..........###..#....##.....#...
...#...#....#.##.#...#.#.......
..##......#.......#.......##...
............#............#.....
.##....#.........#.............
....#....#....#........##...#.#
.......##......................
..........#.#.................#
......##.#...#.........#.....#.
..#...#......#..#.............#
..........###.#..#.#...#..#..#.
#..#.#..#....##...#...#.#...#..
.#........##...#......#.##.....
...###.#...##..............##..
#.#.#...#...#..#....#.#..#.....
.#.#.##..#....#......#.#.......
...#..#.#....##...........#..#.
.....##..##......#.#...........
......#.....#....####....#.....
.#.#.#...#..#..#...........#...
.....#......................#..
.........#.........#.###.##....
.....#......##..........#......
..#...........##...........#...
..............#.........#.....#
..#....#..#...#...##.#.........
.#.#.#....#..........#.........