Init (tm day3)
This commit is contained in:
33
day3/day3.py
Normal file
33
day3/day3.py
Normal 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()
|
||||
Reference in New Issue
Block a user