-
-
Save gnyman/b58aef5a80e97ec2ae2fc1869452eb47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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