Start Picking Apart the Input Stream
00:00
Here, I’ll just, let’s see, let’s call it stream
. Here’s at least the example stream that we had. I’ve already created a file here that I’m calling aoc202206
, so that I have my file that I’ll be running.
00:16 Let’s, just to see that we have something running here, I’ll just print out the stream down here so that we can see.
00:29 Let’s see. I’m not in the correct place.
00:32 See, that’s always a good, good thing of testing where you are. Exactly. I’m going to just print out the stream, save the file, and then let’s try to run the code just to see that we have something up and running.
00:48 So there we’re printing out the stream. Of course, that’s not what our task was. So what are we going to do here? We are going to look for a combination of four consecutive characters and check that they’re all different from each other.
01:04 Let me start with one solution here where I’m just going to pick up the first four characters.
01:15 I’m just calling them first, second, third, and fourth character. And then I’ll just have the rest, I guess. And I’m taking these from the stream. So what I’m using here is just this unpacking of sequences in Python.
01:30
So since stream
is a string, which is a sequence, what I’m doing here is that I’m taking the first character, which will be m
first, and then second
will be j
, third
will be q
, and the fourth
will be j
again.
01:43
And then this star (*
) means that, okay, now just give me the rest of them. So that will then be everything from p
there until the end.
01:52
So the last variable that you defined there is *rest
. So yeah, it’s not just a star, but it’s actually, like, a star in front of a variable name.
02:03
Yes. So the star is kind of like a syntax, and then rest
is a variable.
02:09
So that means that I can look at the first four characters, and at this stage, that means that the marker would be 4
if all of these are different.
02:18
Could you print the first
, second
, third
, fourth
, and the rest
for a moment so we can see what they are?
02:24
Yes. So instead of the stream, we’ll print first
, second
, third
, fourth
, and then I’ll print rest
on a separate line, I guess.
02:38
So now if we run this again, we can see here that first
, second
, third
, and fourth
, those are individual characters, while the rest
is now actually not the text string anymore, but it’s a list of characters.
02:50 So it’s kind of exploded all the characters into a list.
Become a Member to join the conversation.