day06 improved

This commit is contained in:
Ruediger Ludwig 2022-12-07 05:56:47 +01:00
parent fd1467d11e
commit 576bfd0bcd

View file

@ -1,6 +1,6 @@
from __future__ import annotations from __future__ import annotations
from itertools import product from itertools import combinations
from typing import Iterator from typing import Iterator
day_num = 6 day_num = 6
@ -20,11 +20,12 @@ def marker(line: str, length: int) -> int:
Raises Exception if no marker was found Raises Exception if no marker was found
""" """
for pos in range(length, len(line)): for pos in range(length, len(line)):
identical = 0 found = False
for a, b in product(line[pos - length:pos], repeat=2): for a, b in combinations(line[pos - length:pos], 2):
if a == b: if a == b:
identical += 1 found = True
if identical == length: break
if not found:
return pos return pos
raise Exception("No marker found") raise Exception("No marker found")