Find the Example Marker
00:01
So now we should be close to getting our answer actually because, well, this is an if
statement. That’s actually not exactly what we want, but we’ll see what happens now if we just run this. We can see that we have moved on.
00:18
So if we look here on the original, we had mjqjp
, and now we’ve moved one step further and the marker has become 5
.
00:28 I want to move like this until I actually find a place where we don’t have any of these matching. So that means that as long as any of them are matching, we can continue.
00:39
So I can change my if
to a while
statement.
00:43
So that means that instead of just doing the check once, I’m checking continuously until my check fails, really. Let’s try to run that one. And in this case we can see that it’s moved on to jpqm
, which are all different.
00:57
And it says that the marker number is 7
. And if we remember from the web page, 7
was the correct answer for this particular example.
01:06
Okay, so before that you had the if
statement that was basically to verify that the code works, but since it’s only an if
statement, you basically run the code, the if
statement is executed once, and then the marker goes one step further, and then your code stops.
01:25 And since you don’t know where the marker is, so where the first four characters that are different appear, you need to put it into some kind of loop, right?
01:36
You could have, for example—we don’t need to to write this down right now—but you could have used a for
loop and looped through the whole string and then have the if
statement inside of the for
loop body.
01:48
But since you actually just care about the first appearance of the four unique characters, you use a while
loop because you go step by step by step further until the statement is not True
anymore.
02:02
That means that all the comparisons return False
, and then you step out of the while
loop. And that’s basically the solution that you need right there.
02:12 Exactly. This is meant now we can—yeah, I guess we can keep also the printing out the marker makes sense, the actual characters and then the number.
02:23 And now we can move on to actually checking this for the puzzle input.
Become a Member to join the conversation.