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

View File

@@ -13,4 +13,7 @@
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Python 3.6 interpreter library" level="application" /> <orderEntry type="library" name="Python 3.6 interpreter library" level="application" />
</component> </component>
<component name="PyDocumentationSettings">
<option name="renderExternalDocumentation" value="true" />
</component>
</module> </module>