Complete day 3

This commit is contained in:
Peter J. Holzer 2020-12-12 13:28:18 +01:00 committed by Peter J. Holzer
parent 12e300446b
commit 9cc0c3f8d6
3 changed files with 382 additions and 0 deletions

323
03/input Normal file
View File

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

25
03/part1 Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/python3
slope = []
with open("input") as fh:
for ln in fh:
row = []
for c in ln:
if c == "#":
row.append(True)
elif c == ".":
row.append(False)
elif c == "\n":
pass
else:
raise RuntimeError("impossible")
slope.append(row)
xmod = len(slope[0])
x = 0
y = 0
trees = 0
while y < len(slope):
trees += slope[y][x % xmod]
x += 3
y += 1
print(trees)

34
03/part2 Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/python3
slope = []
with open("input") as fh:
for ln in fh:
row = []
for c in ln:
if c == "#":
row.append(True)
elif c == ".":
row.append(False)
elif c == "\n":
pass
else:
raise RuntimeError("impossible")
slope.append(row)
def trees(slope, right, down):
xmod = len(slope[0])
x = 0
y = 0
trees = 0
while y < len(slope):
trees += slope[y][x % xmod]
x += right
y += down
print(right, down, trees)
return trees
t1 = (trees(slope, 1, 1))
t2 = (trees(slope, 3, 1))
t3 = (trees(slope, 5, 1))
t4 = (trees(slope, 7, 1))
t5 = (trees(slope, 1, 2))
print(t1 * t2 * t3 * t4 * t5)