Understand the Puzzle
00:00 So usually, day one of the Advent calendar, the puzzles start fairly straightforward, and they get more and more advanced during December. So here we are at day six.
00:10 So we are still in the beginning stages, getting warm, and as you can see on the screen right now, there is a big blob of text where you see the context for the day six puzzle.
00:21 And that’s actually, again, a very lovely thing about this Advent calendar is you don’t just get a puzzle and need to solve it, but it’s a story that evolves over December.
00:33 And here on day six, we kind of have some tuning trouble.
00:38 Yes, so far in the story, we have been hanging around with the elves, kind of going through a dense forest, I believe, and looking for the star fruits. And in this particular day, we’re kind of moving through the forest, and then we’re getting access to a device.
00:54 One of the elves gives us a device where we need to set up a communication system. And then usually you can kind of skip over the story, but as Philipp said, it’s one of the fun parts of the whole Advent of Code experience.
01:09 But here, essentially what it comes down to is that to be able to communicate with the elves, the device needs to lock onto their signal. So we need to figure out how can we lock onto a signal.
01:21 The signal is a series of seemingly random characters that the device receives one at a time. And to fix the communication system, we need to add a subroutine to the device that detects a start-of-packet marker in the data stream.
01:34 In this protocol, a start-of-packet is indicated by a sequence of four characters that are all different. So that’s kind of what we’re looking for.
01:42 One really nice thing with these puzzles as well is that they give us a worked-out example. So even if all of these words didn’t completely make sense to us, we can kind of see an example that’s coming beneath here.
01:55
So for example, suppose you receive the following data stream buffer. So that’s these seemingly random characters. And then they say that, okay, if you look at the first three characters, mjq
, there haven’t been enough characters to find a marker.
02:09
So we’re looking for four different characters. And then the first time a marker could occur is after the fourth character has been received, making the most recent four characters mjqj
.
02:20
But here j
is repeated, so this isn’t a marker. So remember, what we’re looking for is four consecutive characters that are all different.
02:30
So the first time that we see a marker in this particular example, they say here it’s after the seventh character arrives. So if you look at this, we can see that the first four we have j
repeated.
02:43
And that’s also true if we look at the characters from two to five. Then when we get to three to six, we see that q
is repeated.
02:54
And then finally, once we come down to the fourth, fifth, sixth, and seventh character, we see that these four are different, jpqm
.
03:04
So in this case, we should then create a subroutine that reports the value 7
because the first start-of-packet marker is after seven. And then they add in a few more examples,
03:17 and our question then is stated here once more. How many characters need to be processed before the first start-of-packet marker is detected? And then it says here to begin, get your puzzle input.
03:28 And this I can now click on. And what you’ll see here is that the actual data stream that we will be working with is a fairly big one. So that’s all of these characters.
03:38
But before we start worrying about that, we’ll just look at the examples that they have for us here. So our first task is essentially, let’s implement this and see if we can get the answer 7
from this text.
Become a Member to join the conversation.