Day 3
This commit is contained in:
28
day03/part2.py
Normal file
28
day03/part2.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import operator
|
||||
from functools import reduce
|
||||
|
||||
lines = [x.strip() for x in open("input.txt")]
|
||||
|
||||
pos = 0.0
|
||||
count = 0
|
||||
factors = []
|
||||
|
||||
|
||||
def prod(iterable):
|
||||
return reduce(operator.mul, iterable, 1)
|
||||
|
||||
|
||||
for movement in [1, 3, 5, 7, 0.5]:
|
||||
count = 0
|
||||
for line in lines:
|
||||
if isinstance(pos, int) or pos.is_integer():
|
||||
pos = int(pos)
|
||||
pos = pos % len(line)
|
||||
if line[pos] == '#':
|
||||
count += 1
|
||||
pos += movement
|
||||
factors.append(count)
|
||||
pos = 0
|
||||
|
||||
print(factors)
|
||||
print(prod(factors))
|
||||
Reference in New Issue
Block a user