Day 3 (part 2 array slicing)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -13,4 +13,7 @@
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Python 3.6 interpreter library" level="application" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
<option name="renderExternalDocumentation" value="true" />
|
||||
</component>
|
||||
</module>
|
||||
Reference in New Issue
Block a user