Skip to content

Instantly share code, notes, and snippets.

Created December 6, 2022 13:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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
# If we have more than four characters, remove the first one
if len(last_four) > 4:
# 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:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment