 All right, welcome to day three of admin of code in Haskell Yesterday We were helping the elves with their rock-paper-scissor game. So the lore goes that they're They're on some expedition to the starfruit grove And we collected some starfruit no no first we checked that they had enough calories for the expedition Then we helped them out with their Rock-paper-scissor tournament over or we helped ourselves to decode the strategy guide and Now it's time for day three Let's see what we got today also The video for day one is up the video for day two will be up at like 645 today So check out the YouTube channel right if you want to catch up. Hi, you know you want to watch this dream, but oh Hey, hi a little Annie She is my biggest fan First subscriber even I think We have more subscribers now someone last stream they gave away a bunch of subscription edible monad a fellow Haskell enjoy I also like this part right where they kind of slowly reveal the Yeah, so one problem with this is that it nicely we have 24 days Right, so Christmas is on the 24th in the evening But here it's until day 25 Which isn't let's check out the stats. I want to see See a lot of people do day one and day two people haven't done day three yet But you can always see like it kind of Gets down. All right. Let's do day three of advent of code Okay, so Rocksack reorganization One elf has an important job of loading all the rock sacks with supplies for the jungle during Unfortunately that elf didn't quite follow the packaging packing instructions, so a few items not need to be rearranged Each rucksack has two large compartments all the items of that type Of a given type are meant to go into exactly one of the two The author did the packing failed to follow this rule exactly for one item per rucksack Your alice made a list of all the items currently in each rucksack But they need your help in finding the errors every item that type Every item type is identified by a single lowercase or uppercase letter. That's a Okay, so different letters between different items and then The list of other green characters in a single line given rucksack has a same number of items in each of its two compartments So the first half of each character is represented as in the first compartment I was second half of each care of the character representatives from the second compartment Okay, means okay, so we split the string in half While the second compartment contains the items, okay Okay, so we're supposed to Okay, so we split the items. Okay, I mean we find the common ones To help prioritize re-item rearrangement every item type can be going in a priority Okay, so just couldn't work the letters Can I do this in right now? I just want to think about the Is our function a don't go to GCI import data.char Now we're gonna use type tolls. I Implemented this in GC did it to int See it's a useful feature digit to int of a 10 be 11 Oh This is not the I want to I think I want to do from enum here the other function Yeah, okay, so it starts off. So like a is this B is this right? So it's like the ASCII character set But it starts with the opposite Okay, so let me just write this a This function first like priority and char to prior right? Let's say module main where Char to prior is gonna take a char and give us an in Now we're gonna import data.char Oh, no, maybe I don't even need that. Oh, it's in the preload. Yeah, I don't need that a Wait, what is this word here or a Okay, it's just the same Function as from you know Okay, a I don't need a chart to prior chart to prior equals Okay, so So said it's gonna be 52 right so we say or Said that's 90 right and then it starts at 97 Okay, so if it's lower case, we're just gonna do minus Okay Let's just do it like There's some mathematical formula we could use here It's lower Okay, so it's lower C is It's lower C equals From enum C. Okay, so then we get the 97 and then we want to do 97 minus 95 95 otherwise otherwise it's going to be let's say Where IV this is in 12? So here we say from you know IV a IV minus 95 and otherwise it's IV minus so a big a is 65 but it's supposed to be 27 I want to say 65 minus 27 So, yeah, it's a 65 minus 38 is 27. Yeah, don't worry. I got a math degree They don't really teach arithmetic in math degrees actually so you want to do minus 30 Okay, we got a chart to prior Function and now we get the strings this time. I'm just gonna Yeah, let's do it for the example new file Example, okay Paste it. Okay. So what I'm actually gonna do is I'm just gonna convert them to priorities Right away, okay, so read input is gonna be a File path to List of list of units I Read input equals do F read file read file FN then I want you to do Lines so we want the lines. Okay, let's just do the same without And then I want to do F map a Want to do lines and then I want to do map chart map map Char to prior And now it doesn't like it because Okay, where and now we just Huh, see it's all about clean code Main IO, okay main equals Example Now there's something wrong here FN is no longer there. Okay, I think we need to do now like this. What is the error here? Expected because we do F map lines Expected so now read file. Oh, they turned off the type whole plug-in Got a new follower off Martin Actually, I'm gonna go into the settings Anyway, I think they turn it on again we changed it Yeah, so this is also the bullshit right and they turned off the type falls integrated into the Into GTC even though it's super fast and now it just doesn't work, right, which is Let me see here, right? So if I do here So I do here I Yeah, it doesn't it doesn't actually give me anything here, right even The error message does say there's a bunch of refinement whole fits, right? But my code completion action Doesn't work, which is quite sad. Um, I should report to somewhere a Because they started Using this other thing and like the wingman thing and the wingman guy He just H type because in the beginning it's true. They were slow But now they're super fast I think this works in the This works in the latest version of each other. So I don't want to see how that works It's quite annoying right because you can just you usually be able to just do total period and then it would just work Okay, and now we have the lines return map map chart To the lines map to this Characters chart to prior. What is this right? I used to be able to do this Can we do this in day two? Okay, this is why it's been going wrong. Okay, now my undo buffers. We had to get to start over module main Okay, import this. Okay. Now this one should be read input file path to I.O. This is what it was I Wrote I.O. I.O. Oh my god. I guess that's what happened I like press tab and then it auto completed and removed it Okay, and I've used no longer there where no it works, right? Okay, you know we're gonna do gco day three day 3.hs and I put the example file in the wrong directory Okay, now we have all the prioritizations Okay So task one so we're going to take a list of pins and we're going to return the prioritization Task one equals exits equals So now we're going to do Split that Okay, so we split it at the length divided by two Right and split at 2 Uh, so let's say where l equals the length Exits now Comp 1 compartment 1 compartment 2 equals split at l Do 2 divided by 2 of x's And now we want to find a The only item that appears in both compartments But I have copies of the items, right? Uh This is Overkill, uh, we're not gonna use sets, right? Let's just say data dot list Because I think we can use like some of the set functions. What would this set? right Uh intersect So then we take the Intersect of the list and only one of them should be there. So we're gonna say a Head Intersect Comp 1 Comp 2 this is from data dot list Import data dot. I mean this is not fast. We should really like convert it to a set and then to the intersect But uh We're doing it once so if it's task 2 is like I'll do it a million times so we can do it Right, but uh, that will be premature optimization, right? and 17 38 42 16 38 42 Then it says 20. Okay. So we're just off by one with if it's lower. Yeah makes sense. So it was 96. Okay. So 16 38 42 22 2019 and the sum of that is 157. All right. Now we got it. Let's do our input here input. All right Day three input 75 53. Let's see if that's correct We did task one Now let's see how long it takes to take test Okay, actually finish it and let's come up with a different issue for safety. The elves divided into groups of three It's of course your budget Uh That is group Spanish item type B. Then all three elves will have item type B somewhere in the rucksack And the most two elves will have to be carrying the other item. Oh, okay That is the only item type carried by all three elves That is if a groups match Is item type B then all Three elves will have item type B somewhere in the rucksack and the most two of the elves will be carrying any other item type So all three elves will have type B Uh, and the most two of the elves Will be carrying It's by finding the one item type that is common between all three elves in each group Every set of three lines units comes from the single group with each group having three different batch items I don't get like all three elves will have item B somewhere in the rucksack And the most two of the elves will be carrying any other item type Okay, uh First groups rucksack are the first three first three lines second groups are the three lines Okay, so I don't get this carried by other item types, but I think we can just ignore that uh To pass to So first we're going to define the chunks function, right? chunks chunks takes an int and a list Of aids and returns a list of lists of aids now chunks and equals A So what we do here is we do An axis okay equal so case length axis me equals If it's less than or equals to n Then we just return axis. Otherwise let uh s r Equal split add n Exes and then we return in a s chunks So what this is going to do is going to split up the things into three, right? So great input Example example print Chunks three List Uh, okay chunks zero Okay, so now we've got a two lists of threes. Okay so task two Task two it's going to be first of all Going to be a list list of pins to It's going to I mean it's going to return the sum in the end task two. Okay so uh where threes equal threes Chunks three Uh, okay in so here we got the uh Inputs, okay, and then we're gonna do Uh Sets and now we're gonna do you sets actually import data dot set as set qualified Import data dot set set. We don't actually need that. Okay, so we don't do Sets we're gonna map set dot from list to the threes Now I have a list of sets. Okay, then a Intersects equals Ah, so we don't do the map map. Okay, exactly so Let's just be undefined But because you want to type check the rest, okay a So threes These equals list of list of list of hints So this is going to be because we're chunking it up Sets Is going to be a list of List of sets now a Interts equals map. So this is going to be list of sets And inters is going to be map set dot intersect Can I do intersection here? Uh set that intersection I think we have to do full map of the sets Okay, now these should all be containing one element So we're going to say who We're gonna say data dot set data dot set So we're gonna take like the minimal element Let's just use So I can actually do a yeah, man minimum maximum doesn't matter And so we're gonna do uh some map minimum Interests so we get 70 for the first one Now let's see what is this for the input 2758 let's check if it's correct We completed day three in 30 minutes, not bad Not bad at all. I like the You know just like it's quite simple, right? We just do do do do. So Uh, we use set here. We probably it would be probably nice today to do Something like this, right? These are already importing set, right? Just uh, yeah keep it smooth All right. Hey, yeah super short today again. Um, I like these So this is just a bunch of set intersection and Let's go back to the lore. What do we do? Yeah, we help them with the rugs hex That's great. All right kids Hey people Whatever you prefer to call yourselves Here's a short stream today. Um We'll be doing longer streams. You know once the difficulty kicks up But yeah It's Saturday Happy weekend. Enjoy your December And uh, you see tomorrow same time Two o'clock We do a quick session And that's it All right Bye-bye