Init (tm day3)

This commit is contained in:
2020-12-06 15:47:12 +01:00
commit 4d05cc0bb9
7 changed files with 1405 additions and 0 deletions

33
day3/day3.py Normal file
View File

@@ -0,0 +1,33 @@
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()