Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Behold: The Twist

00:00 If you were a little bit scratching your head with the solution that Geir Arne was doing so far, coming like maybe more from a programmer’s mindset where you’re thinking like, okay, that seems very hard-coded what you’re doing there with first, second, and third.

00:15 What if some parameter would change? Then you were exactly right because part two wants you to elevate your code a little bit. So let’s see if the code that you wrote so far, Geir Arne, holds up to this new challenge.

00:30 Yes. The approach that we chose here was kind of to make a small point, I guess, because here in part two, it says that we are correctly detecting packets, but the device still isn’t working.

00:41 It seems like we also need to look for messages, and apparently these start-of-message markers, they work just like the start-of-packet markers, except that they are looking for fourteen distinct characters rather than four.

00:53 So we kind of just need to do the same thing we did in the first one, but for fourteen characters instead of four.

01:00 Then it kind of repeats the same examples that we had in the previous one and says, for instance, this mjqj stream that we were working with in the beginning, the first message marker comes at character 19.

01:12 So we can kind of reuse those examples.

01:16 So let’s go back to the code and think a little bit about what we did here.

01:21 I’m going to, let’s see, comment out the long example or the actual input text and just go back to the previous example.

01:30 The logic that we used here is sound. We can definitely continue the logic, but I think this approach is kind of not very scalable because what I would now need to do here to also handle fourteen would be that I’m starting doing fifth, sixth, seventh, and so on.

01:48 One thing is to do those here, just picking it out from the stream.

01:53 But I would then also need to look for all of these combinations, and that would be close to a hundred combinations or something like this. So we should rethink a little bit how we’re working with this. Instead of directly working with part two, I’m going to redo part one in a more efficient manner, so to speak, where we can use the number four more like a parameter than something that we hard-code into the code here.

02:17 Yeah, it’s a good idea to not jump into part two right away and come up with a new solution that works for part two, but to take a step back and say, like, the first approach doesn’t work for part two, but coming up with a new approach that works for part one and for part two.

02:36 And what is kind of the connecting part, which is the marker number, right?

Become a Member to join the conversation.