def get_trees(world, slopes): result = 1 for dx, dy in slopes: trees = 0 x = 0 y = 0 while y < len(world): if world[y][x] == '#': trees += 1 x = (x + dx) % len(world[y]) y += dy result *= trees return result with open('input.txt') as fh: world = [line.rstrip() for line in fh] print(get_trees(world, [(1, 3)])) print(get_trees(world, [(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)]))