From 6c0f46fd2b08198f9c1e6dee56b225dc6b694d32 Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Mon, 4 Dec 2023 01:29:42 +0000 Subject: [PATCH] day 3 slight simplification --- day03/sol.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/day03/sol.py b/day03/sol.py index f21209a..a48bc05 100644 --- a/day03/sol.py +++ b/day03/sol.py @@ -38,19 +38,18 @@ for no, line in enumerate(data): i = j else: i += 1 - + for n, pos in zip(digits, places): if any(nexttosymbol(no, i) for i in pos): print(n) part1 += n - seen = set() + nearby_gears = set() for i in pos: - for g in findgears(no,i): - if g not in seen: - gears.setdefault(g, []).append(n) - seen.add(g) - + nearby_gears.update(findgears(no, i)) + for g in nearby_gears: + gears.setdefault(g, []).append(n) + print(part1) part2 = 0 @@ -58,11 +57,3 @@ for g, nums in gears.items(): if len(nums) == 2: part2 += nums[0] * nums[1] print(part2) - - - - - - - -