Start Picking Apart the Input Stream
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: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: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.
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
third will be
q, and the
fourth will be
So now if we run this again, we can see here that
fourth, those are individual characters, while the
rest is now actually not the text string anymore, but it’s a list of characters.
Become a Member to join the conversation.