import operator from functools import reduce lines = [x.strip() for x in open("input.txt")] pos = 0 count = 0 factors = [] def prod(iterable): return reduce(operator.mul, iterable, 1) for x, y in [(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)]: count = 0 for line in lines[::y]: pos = pos % len(line) if line[pos] == '#': count += 1 pos += x factors.append(count) pos = 0 print(factors) print(prod(factors))