Skip to content

Instantly share code, notes, and snippets.

@abeland
Last active December 6, 2022 05:27
Show Gist options
  • Save abeland/dfe4e6425c0431ebe6c6c60a0ce6fa7f to your computer and use it in GitHub Desktop.
Save abeland/dfe4e6425c0431ebe6c6c60a0ce6fa7f to your computer and use it in GitHub Desktop.
from collections import deque
from input import INPUT
def _detect_start_of_msg(s: str, n: int) -> int:
d = deque(s[0:n])
i = n
while len(set(d)) < n:
d.popleft()
d.append(s[i])
i += 1
return i
def part1() -> int:
return _detect_start_of_msg(INPUT, 4)
def part2() -> int:
return _detect_start_of_msg(INPUT, 14)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment