Day 3 (part 2 array slicing)

This commit is contained in:
Sebastian Seedorf
2020-12-03 11:47:50 +01:00
parent 13774dedbb
commit 32e3e95370
2 changed files with 10 additions and 9 deletions

View File

@@ -3,7 +3,7 @@ from functools import reduce
lines = [x.strip() for x in open("input.txt")]
pos = 0.0
pos = 0
count = 0
factors = []
@@ -12,15 +12,13 @@ def prod(iterable):
return reduce(operator.mul, iterable, 1)
for movement in [1, 3, 5, 7, 0.5]:
for x, y in [(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)]:
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
for line in lines[::y]:
pos = pos % len(line)
if line[pos] == '#':
count += 1
pos += x
factors.append(count)
pos = 0