with open('data-2022-06.txt', 'r') as f:
inp = f.read()Advent of Code 2022 Day 6
— Day 6: Tuning Trouble —
We are on our way!
However, because he’s heard you have significant experience dealing with signal-based systems, he convinced the other Elves that it would be okay to give you their one malfunctioning device - surely you’ll have no problem fixing it.
How many characters need to be processed before the first start-of-packet marker is detected?
Loop and find four distinct in a row
len(inp)
for i in range(3, len(inp)):
t = inp[i-3:i+1]
if sorted(list(t)) == sorted(list(set(t))):
print(i+1)
break
# 18961896
— Part Two —
Start-of-message markers are 14 unique characters.
How many characters need to be processed before the first start-of-message marker is detected?
for i in range(14, len(inp)):
t = inp[i-13:i+1]
if sorted(list(t)) == sorted(list(set(t))):
print(i+1)
break
# 34523452