adventofcode.com/2020/03/03b.py

75 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python3
# Advent Of Code 2020 - Day 3
"""
...#.#..#..#..#..............##
.##.......###.#......#....#..##
..##.##.#......#....#..#...#..#
..##.......
Right 1, down 1.
Right 3, down 1. (This is the slope you already checked.)
Right 5, down 1.
Right 7, down 1.
Right 1, down 2.
multiply all runs
"""
#[right,down]
runs = [[1,1],
[3,1],
[5,1],
[7,1],
[1,2]]
filename = "input.txt"
with open(filename) as f:
content = f.readlines()
treesTotal = 1
totalRows = len(content)-1
totalColumns = len(content[0])-1
print (totalColumns)
print (totalRows)
for run in runs:
x,y = 0,0
moveRight = run[0]
moveDown = run[1]
trees = 0
row = 0
while x < totalRows:
x = x + moveDown
y = y + moveRight
# didn't bother changing the while loop, so here we check if we are over the end
if x > totalRows:
break
if y >= totalColumns:
y = y - totalColumns
if content[x][y] == "#":
trees = trees + 1
row = row +1
treesTotal = trees * treesTotal
print (treesTotal)