aoc2022/d06/part2b.py

14 lines
378 B
Python
Raw Normal View History

2022-12-06 15:27:05 +00:00
import sys
from collections import deque
dq = deque()
for (i,c) in enumerate(sys.stdin.read()):
equals = list(filter(lambda x: c == x[1], enumerate(dq)))
if len(equals)>0: # remove left part until a char equal to c, included
for _ in range(equals[-1][0]+1):
dq.popleft()
if len(dq) == 13: # if we have 13+1 distinct chars, we're good
print(i+1)
break
dq.append(c)