From 576bfd0bcd21497b0008c1dc574f451b8093325b Mon Sep 17 00:00:00 2001 From: Ruediger Ludwig Date: Wed, 7 Dec 2022 05:56:47 +0100 Subject: [PATCH] day06 improved --- advent/days/day06/solution.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/advent/days/day06/solution.py b/advent/days/day06/solution.py index 33125c2..878dbea 100644 --- a/advent/days/day06/solution.py +++ b/advent/days/day06/solution.py @@ -1,6 +1,6 @@ from __future__ import annotations -from itertools import product +from itertools import combinations from typing import Iterator day_num = 6 @@ -20,11 +20,12 @@ def marker(line: str, length: int) -> int: Raises Exception if no marker was found """ for pos in range(length, len(line)): - identical = 0 - for a, b in product(line[pos - length:pos], repeat=2): + found = False + for a, b in combinations(line[pos - length:pos], 2): if a == b: - identical += 1 - if identical == length: + found = True + break + if not found: return pos raise Exception("No marker found")