Skip to content

Instantly share code, notes, and snippets.

@gnyman
Created December 6, 2022 13:28
Embed
What would you like to do?
# Parse the input
data = open('input.txt').read().strip()
# Keep track of the last four characters received
last_four = []
# Process each character in the data
for i, ch in enumerate(data):
# Add the character to the list of last four characters
last_four.append(ch)
# If we have more than four characters, remove the first one
if len(last_four) > 4:
last_four.pop(0)
# If the last four characters are all different, we have found
# a start-of-packet marker, so print the number of characters
# processed and stop
if len(set(last_four)) == 4:
print(i+1)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment