day4 so far + formatz
This commit is contained in:
13
day3/day3.py
13
day3/day3.py
@@ -1,10 +1,12 @@
|
||||
lines = []
|
||||
|
||||
|
||||
def load():
|
||||
global lines
|
||||
file = open("day3/input.txt")
|
||||
lines = file.readlines()
|
||||
|
||||
|
||||
def trees(right, down):
|
||||
width = 0
|
||||
height = 0
|
||||
@@ -13,21 +15,24 @@ def trees(right, down):
|
||||
|
||||
while height < len(lines):
|
||||
line = lines[height]
|
||||
if(line[width % line_width] == "#"):
|
||||
if (line[width % line_width] == "#"):
|
||||
count += 1
|
||||
width += right
|
||||
height += down
|
||||
|
||||
return count
|
||||
|
||||
|
||||
def part1():
|
||||
print("Part 1: %d"% trees(3,1))
|
||||
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)
|
||||
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()
|
||||
part2()
|
||||
|
||||
Reference in New Issue
Block a user