day06 improved
This commit is contained in:
parent
fd1467d11e
commit
576bfd0bcd
1 changed files with 6 additions and 5 deletions
|
|
@ -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")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue