 Hey, how's it going everybody? My name is John Hammond and in this video I want to crank out the challenge solution to the challenge prompt early yesterday hazy days And that is the day before the day after tomorrow is Sunday So a person had to take her cat to the vet the day before the day before the day after tomorrow When was that so we can figure this out pretty easily just by thinking through it If we know the day before the day after tomorrow is all one quantity and that's equal to Sunday easy enough We just want to know the day before that old quantity And if that's Sunday, we just know the day before that is Saturday So let's uh, I'll just display this out here if I run that solve function and I guess Just talk about a little bit more if we have today today being Let's see the day before the day after tomorrow. So we know tomorrow is today plus one the day after tomorrow is That tomorrow plus one because it's another day after that and we want to know the day before that So we will subtract one And since those who will cancel out will not have today plus one which is equal to tomorrow, right? So that's saying that tomorrow is what is equal to Sunday. That means the day before it would be today Which would also be Saturday. That's easy enough to figure out At least mentally. Let's see if we can get Python to figure that out for us So this is like I said, this isn't really necessary to do through a I'm gonna import a modular I'm the important calendar, which is a cool module or library to handle dates and time stuff If you haven't seen it before definitely check out the documentation But yeah, so this code isn't necessary, but it's a good exercise And if if you haven't seen calendar before it would be a good excuse to look into it So calendar has this cool thing calendar dot day name and That's essentially a list of week day names So I can print out calendar day name zero and that's Monday day name one will be Tuesday, etc And it acts kind of like a list like we can check out the length and everything blah, blah, blah We can iterate through it. We can do four day in Calendar dot day dot day name and we can print the day Etc etc etc, but it is not actually a list Like I'll show you this if I print this out. It's actually a calendar localized day index So I can't run dot index of Sunday Do you like a numerical value of? Sunday, so we're gonna have to fix that up really easily. We can just do some list comprehension like that We can use weekdays equals. I guess weekday for weekday in a calendar dot day name, which seems pretty Dumb right because we're literally just looping through a list to get a list out of it But now we should have weekdays that we can actually access and see it now So now it's a full that's a full list sweet So that's just simple one-liner, but let's see if we can actually have Python figure out now To what today would have been I'm gonna do that with SimPy since right now we can have a Numerical value of Sunday It doesn't have to be it doesn't have to actually be Seven like I'm sure you'd expect it to be like if we started or I guess zero in this case If we started a week on week of Sunday as day zero in the week or the first day of the week It's fine to have it be okay. It is zero right now. Perfect. Whatever Regardless the value doesn't particularly matter. We should still be able to figure out a value. Let's watch this If I actually do today equal to a symbol and a Senpai So we just have a variable for it now. We can pretty much solve an equation, right? We can say the day I'm just gonna use that to store the value the day equals Senpai solve And we'll set up an equation We'll say that today being the current day just like I did earlier today plus one is gonna be tomorrow The day after it is gonna be plus another one the day after So I'm just gonna compress that to plus two right and the day before that so minus one Which is again plus one which is gonna equal Sunday. So again, this really just mentally or at least Programmatically like an equation. We'll solve the same mental equation that we just did earlier But you can express it as explicitly if you want to because that's you're just doing it your own way and Let's just set that equation equal to Weekdays dot index of Sunday. So if we're saying that a the day after tomorrow and the day before that Expand it out really is equal to Sunday. We want to be able to solve for today. Now if I print out the day It'll tell us Symbols my bat five it tells us the day is being five Now I'll just get the first value out of that. So numeric value Now I can print out weekdays indexed at the day zero and It'll tell us that hey that day is Saturday So now today is pretty much Saturday. That's what we just solved for and that was everything we already conceptually figured out, right? We're saying that today Plus one being tomorrow the day after that plus one and then minus one being the day before that is equal to Sunday So you simplify all this math out? You solve for today That's easy enough We're just having Python do that for us and we're using we're creating a cool little list of weekdays that we just kind of put together in a One-liner with the challenge. I'm sorry with the calendar library set up an in equation Which we pretty much just solve for very easily because it's such a simple equation We're just telling Python to do it for us. So easy enough that's how we solved hazy days and Since this is kind of extensible we can do this for any challenge like this which we'll probably see it again Maybe soon, but that's how you can work with those mind-bending time-bending problems that you might see but Again, this one was pretty easy, but again the conceptually having Python do it for us is kind of cool So thanks for watching guys. Hope you enjoy this. I'll see you later