 All right Welcome to today's habit of code Wait, am I hurt? Yeah, I think so All right, I think it works All right so Today we're gonna be doing some We're gonna be doing some Advertisement code again We did yesterday Took us a while to get started, but We managed so Today Let's see what we can do We're not gonna be too long today, I think I mean usually we take like Half an hour hour like the first days are very easy, right? But then It gets progressively harder. All right, let's look at today's task. Oh, and also, yeah, I updated my GTC Got new Haskell language server. So Everything works right this time Probably don't need it like we didn't need it yesterday, but yeah, it's nice to have some ID support, right? All right So what's happened so far is that the elves were traveling through some forests? Wasn't quite sure why actually, but We're waiting to Let's actually go back in. Yeah digging to the lower a bit Yeah, so we're So where does this actually say the lower right like we just get Some calorie. Okay, we're going to the annual expedition to the Grove Where the fruit grows? Okay, I mean, this is not as good lore as before right there was better kind of our saving Santa We're helping said now. She's like, oh, we're gonna trip to collect food Anyway, maybe there's a twist. Maybe the lore will improve, but you know This is more about the gameplay and not the law all right, so we're on our way there and And now the elves have set camp up on the beach and they're gonna be playing a rock-paper-scissors tournament Okay Right, I mean we now rock paper scissors work. Okay Scissors to face paper blah blah blah Appreciative of your help yesterday one of y'all gives you an encrypted strategy guide. Well This will be sure to help you win the first column is what your opponent's gonna play a for rock B for paper C for scissors The second column That's all the elf is called away to have with someone's tent The second calling your reason must be what you should play in response X for rock why for papers have a system Winning every time would be suspicious. So the responses must have been carefully chosen The winner of the whole tournament is a play with a highest score your 12 scores some your scores each So we get this So you're on the score for the shape you selected one for rock for paper scissors Plus the score for the outcome of the round Okay, so let's calculate the score From the strategy Uh-huh, so I'm guessing now we're gonna be calculating it based on this one And then we're gonna be trying to find like an optimal strategy Sounds good. All right, so let's copy this input in there I have fully Already created Like the framework file, you know some prep goes into these Streams, right? All right, so let's say example All right, paste it Okay, so I guess We are just gonna read the input. Okay, so Um Read input just gonna take the in the file path and then give us an IO of Pears of Let's just say I'm calling moves. Okay, let's define data moves equals Rock or paper or a scissor Driving show eq or don't let just Okay, so we're gonna be giving a pair of moves comma moves. Sorry Now let's write the function that goes Esther to move So we could just go character to move, but we're gonna do it like a string to move a Is equal to a for rock be for papers a for scissors g equals rock e is gonna be Scissor Esther to move She is gonna be I don't know be for paper, right paper and then Okay, and now let's make it work for our moons x no X for rock why for paper said for scissors, okay said Read input equals do okay, so F is gonna be read file We're gonna do line read file Okay, this is gonna be file name read file filing, okay You know we could be clever here, but let's just not okay Let ours line, so it's gonna be a three character string so it's gonna be C and then space and then Column let's call this so you call them one and then column two and then empty string C1 comma C2 now. Let's actually change this to Characters Chop to move Okay, this is oh This should be a move, okay now and then we do And then we do a square parsed line Equals this so there's no safety here, but that's okay a map parsed line Boom now. Let's say just see what it says Read input Example into Print what does it say? Okay, we need to go GC see we got the fancy one 9.4.2 that's good stuff Alright, we run G8 C let's go Day 2.HS 3, oh day 2 and then we're gonna run day 2 Rock paper paper rock scissor scissor So it was okay, so I got the moves Okay, so score round Think we're gonna score for the paper shape you selected. Okay, so okay, so score round Score round is gonna take a pair of move comma move That's actually just to find Equals it's gonna be a list of and score round is gonna taste around to it Okay, so Cell score, okay, selection score is going to be Cell score equals Rock equals one paper was two right? And says it was three Scissor and then okay, this is a Cell score is moved in so it's gonna be Cell score me plus plus Score for the outcome of the round zero if you lost three for round of the draw six Okay, so Okay, that should actually be This should actually be this right score around this was That's actually just to move to move And then we say Rock beats paper Ah But the opponent does first Okay, so we'll say Yeah, there's a rock beats paper. So we get zero if that's the case Paper beats scissors so that's zero and Scissors be paper Okay, so those are going to the zero rounds if we lose Now we're gonna flip all of these Let's see Now these are all gonna be three Okay So rocks be paper paper scissors is a piece of paper paper rocks. It's just paper anything else. They are equal, right? No, this was gonna be six, right? I'm making maybe group And this should be Okay, so Paper so if I play paper they play rock. I should get five places. There's a play rock that gets zero If I play scissors they pay paper I get six if they play Paper I play rock I get zero and if I play rock Six and then this is Yes, okay, and otherwise it's true All right round scoring function done Then we'll do total score That takes a round and gives us an eight. No total score Me no, this is gonna be up and me It's gonna be a cell score me plus Plus our plus Score Plus score Score around me Okay, now It all works. So now we're gonna do this and and then we're gonna Not just print. We are going to Map a score first. So we get eight one five. Let's see that matches here So first one is eight then we get one and then we get six The third round the draw will play a shooting scissors giving you a score three plus three equals six of cells score. Ah, this was three Sorry, this is why we test, right? Sandy check done eight one six Okay, now let's get our puzzle input Let's have a new file And put and let's run it back. Oh, yeah, sorry. We didn't do this some actually So we just do Some one three five six five, let's see. All right, first gold star Now let's see what's gonna happen in part two. So you know we're doing it quick today And Also tomorrow Because it's the weekend and Surprisingly enough, I want to do things on the weekend. So I'm gonna I think I'll do it around like two o'clock Right European time, right? So Yes, I kind of do it, you know doing the more like not in the morning, right? I don't want to wake up But I do it afternoon and then I can do whatever in the evening So if you want to join tomorrow, it's Two o'clock. All right. Anyway, the second column says how the round is and X means you need to lose Y means you need to end the round in a draw and Said means you need to win. Good luck Okay, we don't have to figure out the strategy. We just have to figure out a Figure out what shape to choose the round rinse as indicated This is just a big statement, right? Okay, so lose draw win Okay, okay. So I want to do this in a clever way okay, so So this was a part one equals sum dot map Okay print dot part one So now we're gonna do part two to Okay, let's click here get this annotation Part two So it takes in Part one two takes in a Okay part two It goes part two prime Something okay, so how do I do one round here? print Dot Okay, it's going to be part two prime You can take a move and a move and a And return ah So we choose and then we score the round. Okay part two prime okay, so it's So let's see here So part two Up and then res Okay, so because it's already a move. So let's just say rock here we need We need to lose Okay Paper here we need to draw So why was a draw and said was win? a You need to win. Okay So this is win Okay, so, uh Let's derive enum here No So what I want to do is I want to click take This is win. Oh, sorry Okay, so, um This is So what I want to do is I want to I'm going to take the Where um Scores Okay, so let's uh, let's actually Do it in a different way. Let's just call this This is Okay, and now we're gonna do like case matching here. So we're gonna say Uh, if we get rock under the res We need to win Here we need to uh paper out of the rest we need to scissors Scissors From the rest we need to Lose. Okay. So now we have it all in the same thing. I was aware Uh other res equals. So we're gonna say, uh, we're gonna say a map score round hop Over all the moves from rock to This is you get what I mean a other red. So This will tell us a What the other res is Let's actually do here score round I think if you sort on pairs you always sort by the last one, right? Sorry a One two I think this default sort is a Oh you're sorting the first one Okay, so we're gonna ah We got a new follower. Oh Not bad. I got five wheels That is less than yesterday, but it's not that uh, okay, so we're gonna say Okay This is gonna be score round up and and and Okay, uh, and then we're going to sort this Right and then We're going to take this second one So now then we've kind of gotten a list of moves we need to take So for the win we need to select the biggest one So this will be other res A2 this will be other res one And this will be other res zero So, um So other move Equals case res of let's just do it this way Other move a in equals case res res of fellow Haskell enjoyer. Yeah It is the best language to paper users You know, if we actually defined this in the opposite way, this would be super easy but We didn't do it Um, let's not do this paper scissors Okay, uh, and sword is not in the prelude, which is hilarious Okay, what do you call anyone couldn't measure the type with uh, uh, what was that? I got two sub community subjects I have no idea what that means That was not there before but Ah, you have subs now. Wow Nice things ahead of a moment. I'm still in like thought here wait, and So this is the other move we have to pick if this type checks, but it doesn't right so Uh Couldn't match the magic type. It won't be okay other res Oh Maybe I need to do uh, okay. Yes. Just give me the wrong thing other res is a list of uh Moves, yeah S&D Okay, and so This will actually be We're going to say total so we're gonna say, uh Uh Equal to total score Of up and Uh other, uh Dollar other move in Now let's map this over the example Uh, and let's see what it says 492 Oh, we're supposed to get four one seven Ah We need to reverse this boom four one seven I think there's a thing to do this like a function that goes from enum to like int right enum a a to From enum So then we just don't reverse it and this one will be a From enum res Let's just fancy it up a bit Still the same. Okay cool Uh, and then we take the sum of this I guess Yeah part two equals A sum dot map part two prime. Okay run on the example 12 input 12424 Let's see All right, we did part two Uh, and it took us 30 minutes See the first days are quite uh Quite nice. It's a bit You know we get started You get our groove on we got our setup going People are aching For more, uh Advent of code in haskell but It's gonna get a lot harder. I think like the first 10 days will be like, uh, okay And then it like Then it starts getting really hard and then it starts getting So like, you know date 10 is like, that's okay It's a bit hard. It'll take you maybe an hour or an hour and a half You have to not just do it but also think about the performance and then It starts getting super hard Hey like day 16 and you're like, oh my god All right, but uh Yeah, so Thanks for tuning in today Uh, not a long stream today Here for a good time not for a long time as they say, but um Yeah It's gonna be like this for the first couple of days, but thanks for tuning in and uh Yeah, so two o'clock tomorrow so Four hours before this one started so in 19 and a half hours, we're gonna do uh advent of code day three And and then you know people have their evenings free, right? You don't have to be Tuning in on a Saturday night But uh, yeah, thanks for tuning in and uh, see you tomorrow. Hopefully All right. Bye. Bye Uh, I need to sit like this. Yeah All right. Bye. Bye