Files
AoC-2020/day3/day3.py

39 lines
632 B
Python

lines = []
def load():
global lines
file = open("day3/input.txt")
lines = file.readlines()
def trees(right, down):
width = 0
height = 0
line_width = 31
count = 0
while height < len(lines):
line = lines[height]
if (line[width % line_width] == "#"):
count += 1
width += right
height += down
return count
def part1():
print("Part 1: %d" % trees(3, 1))
def part2():
count = trees(1, 1) * trees(3, 1) * trees(5, 1) * trees(7, 1) * trees(1, 2)
print("Part 2: %d" % count)
if __name__ == "__main__":
load()
part1()
part2()