advent-of-code/2022/day6.py

18 lines
371 B
Python
Raw Normal View History

2022-12-06 08:03:22 +00:00
# -*- encoding: utf-8 -*-
import sys
def index_of_first_n_differents(data: str, n: int) -> int:
for i in range(len(data)):
if len(set(data[i : i + n])) == n:
return i + n
return -1
2023-01-06 12:48:18 +00:00
data = sys.stdin.read().strip()
2022-12-06 08:03:22 +00:00
print(f"answer 1 is {index_of_first_n_differents(data, 4)}")
print(f"answer 2 is {index_of_first_n_differents(data, 14)}")