Skip to content

Commit 6ec41ce

Browse files
committed
Create function that returns index of the first start-of-message marker
1 parent 49700bf commit 6ec41ce

File tree

1 file changed

+5
-1
lines changed
  • puzzles/solutions/2022/d06

1 file changed

+5
-1
lines changed

puzzles/solutions/2022/d06/p2.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55

66

77
def get_answer(input_text: str):
8-
raise NotImplementedError
8+
"""Return how many characters need to be processed before the first start-of-message marker is detected."""
9+
for index in range(START_OF_MESSAGE_MINIMUM_UNIQUE_SEQUENCE_LENGTH - 1, len(input_text)):
10+
sequence = input_text[index-START_OF_MESSAGE_MINIMUM_UNIQUE_SEQUENCE_LENGTH:index]
11+
if len(set(sequence)) == START_OF_MESSAGE_MINIMUM_UNIQUE_SEQUENCE_LENGTH:
12+
return index
913

1014

1115
if __name__ == "__main__":

0 commit comments

Comments
 (0)