2020 day 3

This commit is contained in:
Luke Hubmayer-Werner 2020-12-10 19:42:54 +10:30
parent de078fee90
commit f01c268237
2 changed files with 333 additions and 0 deletions

10
2020/day03.py Normal file
View File

@ -0,0 +1,10 @@
import numpy as np
with open('input03', 'r') as file:
treemap = np.array([[c=='#' for c in line.strip()] for line in file.readlines()])
rows, cols = treemap.shape
r = np.arange(rows)
print(f'Part 1: {treemap[r, (r*3)%cols].sum()} trees hit')
slopes = [(1,1), (1,3), (1,5), (1,7), (2,1)]
tps = [treemap[np.arange(0, rows, i), (np.arange(-(-rows//i))*j)%cols].sum() for i,j in slopes]
print(f'Part 2: {"*".join([str(t) for t in tps])} = {np.prod(tps)}')

323
2020/input03 Normal file
View File

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