Metadata
-
Date
-
Tagged
-
Part of series
- Advent of Code 2022 Day 1
- Advent of Code 2022 Day 2
- Advent of Code 2022 Day 3
- Advent of Code 2022 Day 4
- Advent of Code 2022 Day 5
- Advent of Code 2022 Day 6
- Advent of Code 2022 Day 7
- Advent of Code 2022 Day 8
- Advent of Code 2022 Day 9
- Advent of Code 2022 Day 10
- Advent of Code 2022 Day 11
- Advent of Code 2022 Day 12
- Advent of Code 2022 Day 13
- Advent of Code 2022 Day 14
- Advent of Code 2022 Day 15
- Advent of Code 2022 Day 16
- Advent of Code 2022 Day 17
- Advent of Code 2022 Day 18
- Advent of Code 2022 Day 19
- Advent of Code 2022 Day 20
- Advent of Code 2022 Day 21
- Advent of Code 2022 Day 22
- Advent of Code 2022 Day 23
- Advent of Code 2022 Day 24
- Advent of Code 2022 Day 25
-
Older post
-
Newer post
Advent of Code 2022 Day 6
Day 6: Tuning Trouble
https://adventofcode.com/2022/day/6
Today we get a communication device from an elf.
A stream of characters get sent to the device. Your input is the stream it receives.
An example input looks like this:
Part 1
The start of a packet-marker is the first sequence of 4 characters that are all different.
The question asks to find how many characters had to be checked when we detect the first marker.
I looped over sliding windows of size 4. For each window, I check if all characters in it are unique.
To check if all characters in a window are unique, I loop through the window and check if the character at that point exists in the window so far.
The first window that passes that check is the first marker.
The index of that window is the beginning of that 4 character marker.
Add 4 to that index to find how many characters have been received up to that point.
Part 2
The start of a message is the first sequence of 14 characters that are all different.
The question asks to find how many characters had to be checked when we detect the first message.
This code is identical to part1, but that constant of 4 is now 14.