This commit is contained in:
Søren Rasmussen 2020-12-03 07:39:57 +01:00
parent dfca8fceab
commit 2275a65df5
3 changed files with 364 additions and 0 deletions

323
2020/3/data.txt Normal file
View file

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

30
2020/3/main.py Normal file
View file

@ -0,0 +1,30 @@
from pprint import pprint
with open("data.txt", "r", encoding="utf-8") as f:
data = [x.rstrip() for x in f]
def traverse(tx, ty):
x = y = 0
max_x = len(data[0])
max_y = len(data) - 1
trees = 0
while True:
x += tx
xi = x % max_x
y += ty
if y > max_y:
return trees
assert data[y][xi] in (".", "#")
if data[y][xi] == "#":
trees += 1
trees = 1
for x in ((1, 1), (3, 1), (5, 1), (7, 1), (1, 2)):
z = traverse(*x)
print(f"The toboggan encountered {z} trees.")
trees *= z
print(f"Sum: {trees}")

11
2020/3/test.txt Normal file
View file

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