added day 03

This commit is contained in:
Peter Hudec 2021-12-13 21:12:27 +01:00
parent ebb709b4cf
commit 6cdcf92b0c
4 changed files with 372 additions and 0 deletions

323
03/input01.txt Normal file
View File

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

11
03/input01_sample.txt Normal file
View File

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

13
03/solve01.py Normal file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env python
stepX = 3
posX = 0
trees = 0
with open("input01.txt","r") as f:
for line in f:
line = line.strip()
if line[posX] == '#':
trees +=1
posX = (posX + stepX) % (len(line))
print(trees)

25
03/solve02.py Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python
def count_trees(area, stepX, stepY):
trees = 0
posX = 0
for i in range(0, len(area), stepY):
line = area[i]
if line[posX] == '#':
trees +=1
posX = (posX + stepX) % (len(line))
return trees
area = []
with open("input01 .txt","r") as f:
for line in f:
area.append(line.strip())
result = 1
result *= count_trees(area, 1,1)
result *= count_trees(area, 3,1)
result *= count_trees(area, 5,1)
result *= count_trees(area, 7,1)
result *= count_trees(area, 1,2)
print(result)