 Hey, how's it going everybody? My name is John Hammond and welcome back to another YouTube video still looking at the python challenge There's online riddle full of challenges that we can solve with Python and we're on challenge number 18 right now So I'm presented with these two pictures of geese I think Those are geese right geese. Let's let's Google geese. Oh, yeah Yeah, those are Other totally geese others are they swans? Swans There's swans damn that's a hit to my intelligence All right, yeah, here we go Challenge 18 the first part of the challenge the fear of what animal you're actually freaking looking at it's been a while I don't really get out much I go to college In a in a place. That's not really a college. Here we go Trying to find the difference between the image these two images the source here says can you tell the difference? So it's obviously our goal here find the differences. It says it's more obvious than what you might think That's helpful. Thanks a bunch Let's try and poke this stuff in python. I'm gonna save this image in a level 18 folder. I've already got that created I'll save this fire up sublime text My text that are of choice here. I'll get to code a python challenge level 18. Let's call this solve dot pi Okay, let's get a shebang line In environment Python. I literally screw up a shebang line every single time I try to type it And let's just saying take this image apart because right now it is just one image It is just literally one image with two of them side by side. So let's try and split them up image equals image Dot open and I save this Did I say this? I did say this. Yeah balloons that jpeg if it's not already been saved. Please go ahead and save it I just forget everything now I'm getting old and let's size equals width and height equals image size Let's say that image one it can equal. I'm just gonna crop it for one thing So let's go crop from the top left. Well, most left position is zero top position is zero Most right position is width divided by two and bottom position is height I can do this for image two we can say the most left position is width divided by two and Right is gonna be width all the way and then height speed at the same thing again. So now image one equal I Think I can do this right? Let's do it anyway crop image one It's the same thing with image two How can I run image one dot show and image two dot show? Yes, okay. Cool. So now we have these two pictures Let's cut them up Actually, just save them just in case we need them image one dot save image one dot jpeg Do the same thing for image two just run this one more time So they are now saved And let's actually check out the difference between these two of them We can do that with the image chops module again image channel operation Let's image chops It does have a difference function image chops difference difference. Whoa. I'm super zoomed into this page difference Returns the absolute value of the difference between two images. Okay, whatever. Let's try it Let's see if that's actually what they mean because if it is like do that be awesome It is a lot easier than we thought and let's just show that because it'll return image. Thanks sublime text I don't want to okay. We get nothing at least nothing interesting the same picture here Damn it back to the drawing board I guess Here we go to swans It's more obvious than what you might think Okay, well this picture is lighter and this picture is darker That's something this picture is the same picture this picture is a Picture just darkened this picture is the same picture just picture just brightened the difference is there is is is brightness, right? Is that it like light nope, what about brightness? Oh Oh shit, I didn't that didn't get me a 404 Is it the same page control you whoa whoa whoa new hints? Maybe consider deltas dot GZ That's something so let's get back to that deltas dot GZ. Is that a file like an axis? Delta's that GZ. Oh, yeah, it is. Oh sweet. All right, let's save this Let's open that up code Python challenge of 18 deltas GZ. Oh, let's extract the text file out of that cool Now what is this thing? whoa, whoa bunch of hex stuff I think There's a lot of these lines. I'm gonna scroll down. Oh, wow. There are a lot of these Don't know the bought whoa down at the bottom. It's only like the right column looks exists Two columns I can see I can see that would like that divide here in the center, you know over where my cursor is 8950 for E for Seven it looks like and I look like it's the same thing on both ends I have word wrap on right now, so that probably didn't help that much. But yeah, it looks like both of these columns. Oh These must be the deltas as in the differences, right? Yeah, yeah, yeah So this left column must be image one, right and this other hall must be image two, right? Is that what these pictures are if I open this in sublime text FFD 8 FF easier? No, those aren't those hex values That's not right What the heck is it for an image to? No, they're obviously pretty much the same kind of Okay, whatever Delta's our text. There's got to be differences in each of these things Like 60 9b 20 Especially because of all this because of all the stuff at the bottom these this like this exists all its own There's got to be differences here. Oh, yeah, yeah, yeah EB D5. Yeah. Yeah. Yeah. Yeah These are totally different. How do we find the differences between the two of them? cool Python difference Between texts is that what we want? different oh Diff Lib helpers for commuting computing deltas multiple provides classes function for comparing sequences differ Class for comparing sequences of lines of text and producing human readable differences or deltas Okay, that's what we want. We want to compare these lines of text Each line of a differ Delta begins with two letter code something unique to sequence one and something unique to sequence two Okay, that's cool. That's That's like what we want because we have these two columns sequence one and sequence two Can we just look at the differences between them? How do we do that? differ differ I said it was a differ class differ. Where is the documentation for that? sequence matter objects Different objects different objects. I saw that right there different objects Okay, line junk and care junk are looks like filters Different objects are used generated by a single method. Okay compare. Oh sweet and compares two lines of two sequences The lines and generates a delta between them each sequence was contained individual single line strings with ending with new lines Such sequences can be obtained from the read lines Okay, so just have to end with new lines Sure, let's do that. We just have to split up these lines these sequences Let's try and do that in Python I guess we don't need any of this stuff right now Let's open just get the final name for one thing file name equals Delta text Handle handle handle equals open final name handle dot read lines Lines equals You know what I'm just gonna do read dots with the new no cuz that gives me all of them. Yeah, let's go lines And all that clothes Sprint lines. Oh God, oh Sublime text come back to me Sublime text come back. I just had sublime text hang. Don't do that Come back. Okay, so for line and lines Let's split it looks like position here Is it position 55? so sequence One equals line up to the little 55 sequence to equals line 55 to the end and That's all I want. Let's just see if those actually work I'm gonna break out of this. I'm not gonna have it displayed for all of them, but okay sweet. Yeah, it doesn't work And let's just strip these down Sweet, okay, so now we have sequence one and sequence two. That's that's fine Now we can compare the differences between the two of them, right? Oh, we need to flip duh. We need that. We need actual that module Import diff Lib it is built on by the fall, right? Yes. Okay, cool D because it has to be a different object. I said, right? Yep class.differ differ differ I'll just call it differ differ equals diff Lib.differ differ dot compare sequence one and sequence two Comparison we'll call that I guess can I print out? Can I print the comparison? Oh, this is probably gonna break sublime text Let's do this in a terminal then CD level 18 Python solve Okay, looks like to generate. Let's make it a list. Oh god. Oh God Okay, so each of these things. Oh, it has those plus and less than signs. I see kind of That's gotta be it. Yeah, is that what we want for though That's has to be yeah, cuz I mean those are just gonna be the differences between each single bite Bites is that what we want? Let's keep poking. What can we do with this now? I Mean since we now have things that are split up into what is it? What is that? say The documentation tells us there are things that are specific to sequence one specific to sequence two and on both of them So, you know what? Let's try and put these all in their own specific files Can we do that? I mean since these are all hex values. They're probably all hex bites Probably creating an image or something I guess but I mean since we've already given a picture You know freaking swans Yeah, let's do that. Let's say Okay, let's go back to image one or like sequence one Image sure and Let's just create a file for it. Let's just call it sequence one image dot PNG and Since these are all bites that we were probably writing to it Let's write out with a binary thing and then sequence to image equals sequence to image and then both image I Guess let's just call both image both image sweet And we should not have to do that in our For loop, right? Oh, we were taking the difference in our for do we even have to do that? Oh shoot Left and right. That's why it was going at bite by bite. They were different whole different lines. Yeah. Yeah. Yeah Let's split up. You know what? Let's set these two arrays sequence one and sequence two should be their own individual arrays Because that way we're getting each line that has a different thing, right sequence one a pen That line stripped and then sequence two dot append That line stripped Because I mean the thing with our terminal game is I'm just like each individual character. That's just so we want is it Because we want to find differences like this Yeah Now we can compare the two of them and Now let's close all the things we already have if I just final run this sequence one Whoa sequence one image close the same thing Here now let's run this okay, that's a little bit better. Is it God there's so much data. I wish I knew oh My gosh. Oh wait a second The documentation told us that we needed to have these And new line characters right Different objects have to have new line characters. Oh, that's why that's why it's so weird because like it looks I can see full strings here and the minus things. That's damn it new line character New line character perfect now Run this whoa Is that good or bad? Damn it. I wish I knew okay, some of these are being Differenced Some of these are the same on both sides Let's just let's roll with that idea. Let's just take those differences and just leave them. I think So we have all of these images that we can write to those actually create yeah, they did okay now They just don't have anything in them so Comparison is now a giant array full of differences And let's make these actual bites Because those are all Yeah, yeah, these are all like things So four line in results. I guess like for each result Each individual bite can equal line. Oh no each result beginning to the end print bites Don't bring the comparison this time try around this results Oh comparison, I'm sorry Comparison is the name of our list So now we have a bunch of bites Let's actually take these apart splits Okay, oh shit P kill python Okay, so sublime text is still intact. Good. I ran it within sublime text got a little worried And now we want to make these like character bites, right since yeah, we have to make these Hang on I gotta think Kind of make these Bites. Oh Because they're just right now. They're hex values. Oh god. Stop if you could buy them again Because right now they're just ASCII hex values What we should do is we should actually make them bites that Python can like read and write out like real bites So we know with some list comprehension we can just say Obviously, we'll want to make it hex a hex value for real because right now they're just strings like you saw B I guess because we're doing list comprehension will and then 16 base 16 For B in each of these now when we print these Okay, they're each individual bites But they're just numbers right now if we actually get them to be characters Now they will be actual bites Yeah, yeah, yeah, see up at the top here. We have our escape stuff with dash D. Etc. Etc. Etc. Okay, now we have data we can actually work with and write out to files like PNGs. I like actual things If Each result I guess Thought starts with because we now since we want to put them in things that actually are in sequence left or sequence To lady the left or right first one being minus, right? What does the documentation say? Yeah, minuses will sequence one so Starts with minus then sequence one for bites in bites Sequence one will write that stuff sequence one image dot right Bite and then for image to write it if it starts with a plus sequence to Write bite and if it's in both if it's just a space character like the documentation says it's common to both So it's both image Okay, I think that's what we want because then we're writing every single thing each bite in there Let's try it On solve okay Hopefully it did it Both image. Oh god. There is something there Is that oh my god? What is uh, that's both hex dot dash slash hex pin dot html. What is uh fly? Sequence one says fly Sequence two says butter Hum What do those mean? Let's try that's an html one right dots dash hex dash spin that html Oh gosh, and it said That's a hex for slash of an html. So Last hex bin dot html Okay, pluses and minuses it needs the username and password Crap do it Though those must be a sequence one fly and butter fly butter Fly should fly and butter What fly butter Butter what butter. Oh shit butterfly. Oh Level 19 damn That was cool dude definitely is cool. I Guess we didn't even need those images split up then But we ended up like splitting them up on our own the things that were On one side of the Delta's column the other side of Delta's column things that existed in this or not All these bites these are these are these have to be they had to be image bites, right? What else would they be? Some of these are too high or too low to translate to like actual ASCII text value so Yeah And then we just loop through every single bite that we found after we converted them to actual bites man, that's awesome Slick this lip is cool. I'll have to Have to keep that in mind Difflip differences between text All right guys here we go. I mean that's that's a victory. That's a game right there butterfly and been Her hex for slash been the HTML were at level 19. I Have no idea what I'm looking at right now. I guess we'll find out real soon. Jesus All right. Well, thanks for watching guys. Hope you enjoyed this one, and I'll see you soon