2020 - Day 3

This commit is contained in:
Jonas Neugebauer 2020-12-09 15:37:35 +01:00
parent 6e70bcbf72
commit e2d951157e
3 changed files with 373 additions and 0 deletions

21
2020/day3_1.py Normal file
View File

@ -0,0 +1,21 @@
input = []
with open('day3_input.txt', 'r') as f:
for line in f.readlines():
input.append(line.strip())
start = (0, 0)
slope = (3, 1)
def slide(forest, pos, slope):
if pos[1]+slope[1] >= len(forest):
return 0
else:
pos[0] += slope[0]
pos[1] += slope[1]
row = forest[pos[1]]
if row[pos[0]%len(row)] == '#':
return 1 + slide(forest, pos, slope)
else:
return slide(forest, pos, slope)
print(slide(input, list(start), slope))

29
2020/day3_2.py Normal file
View File

@ -0,0 +1,29 @@
input = []
with open('day3_input.txt', 'r') as f:
for line in f.readlines():
input.append(line.strip())
def slide(forest, pos, slope):
if pos[1]+slope[1] >= len(forest):
return 0
else:
pos[0] += slope[0]
pos[1] += slope[1]
row = forest[pos[1]]
if row[pos[0]%len(row)] == '#':
return 1 + slide(forest, pos, slope)
else:
return slide(forest, pos, slope)
start = (0, 0)
slopes = [(1,1), (3, 1), (5,1), (7,1), (1,2)]
result = 1
for slope in slopes:
trees = slide(input, list(start), slope)
print(slope, trees)
result *= trees
print(result)

323
2020/day3_input.txt Normal file
View File

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