Ahora me siento bien con el codigo python

This commit is contained in:
Daniel Cortés
2020-12-03 04:55:31 -03:00
parent 51784c7d82
commit 0202f8bc15

View File

@@ -1,22 +1,30 @@
from math import prod
with open('input') as f: with open('input') as f:
data = [line.strip() for line in f] data = [line.strip() for line in f]
w, h= (len(data[0]), len(data))
width, height = (len(data[0]), len(data)) def count_trees(slope):
slopes = ((1, 1), (3, 1), (5, 1), (7, 1), (1, 2))
result = 1
for slope in slopes:
trees = 0 trees = 0
right, down = slope x, y = slope
while(down < height): while y < h:
if data[down][right%width] == '#': if data[y][x%w] == '#':
trees += 1 trees += 1
right += slope[0]
down += slope[1]
result *= trees x += slope[0]
print(slope, trees) y += slope[1]
print(result) return trees
def solve_a():
return count_trees((3, 1))
def solve_b():
slopes = ((1, 1), (3, 1), (5, 1), (7, 1), (1, 2))
return prod([count_trees(slope) for slope in slopes])
print(solve_a())
print(solve_b())