37 lines
1008 B
Python
37 lines
1008 B
Python
def getMarker(line: str, startOfMessage: bool) -> int:
|
|
|
|
vl: list = []
|
|
length = 0
|
|
for index, character in enumerate(line):
|
|
if length == 4 and not startOfMessage:
|
|
position = index
|
|
break
|
|
if length == 14 and startOfMessage:
|
|
position = index
|
|
break
|
|
if character in vl:
|
|
lastindex = "".join(vl).find(character)
|
|
vl = vl[lastindex + 1 :]
|
|
vl.append(character)
|
|
length = vl.__len__()
|
|
# print(character, "found. new length:", length, vl)
|
|
continue
|
|
vl.append(character)
|
|
length += 1
|
|
|
|
return position
|
|
|
|
|
|
with open("input", "+r") as file:
|
|
f = file.readlines()
|
|
for line in f:
|
|
sop = getMarker(line.strip(), False)
|
|
som = getMarker(line.strip(), True)
|
|
|
|
# print(line.strip())
|
|
# print(f"^ {sop}".rjust(sop, " "))
|
|
# print(f"^ {som}".rjust(som, " "))
|
|
|
|
print("part 1:", sop)
|
|
print("part 2:", som)
|