From 32e3e95370bda3c3163adcde9016a72a390eec54 Mon Sep 17 00:00:00 2001 From: Sebastian Seedorf Date: Thu, 3 Dec 2020 11:47:50 +0100 Subject: [PATCH] Day 3 (part 2 array slicing) --- day03/part2.py | 16 +++++++--------- python-aoc-2020.iml | 3 +++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/day03/part2.py b/day03/part2.py index e11f0a8..2974997 100644 --- a/day03/part2.py +++ b/day03/part2.py @@ -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 diff --git a/python-aoc-2020.iml b/python-aoc-2020.iml index 1e36f4d..f5ec54c 100644 --- a/python-aoc-2020.iml +++ b/python-aoc-2020.iml @@ -13,4 +13,7 @@ + + \ No newline at end of file