 All right, welcome to today's stream We're doing it again advent of code 2022 and Yeah, this was fun last year It's been fun the year before that and it's gonna be fun again We're doing advent of code in Haskell And yeah Let's see how it goes. You can see I haven't opened the code yet. I did make a well, not a repo, but Short module where I'm gonna be working on and Yeah so Let's get started. Let's see what today's task is All right calorie counting Santas reindeer typically eat regular reindeer food But they need a lot of magical energy to deliver presents on Christmas For that their favorite snack is a special type of star fruit that only grows deep in the jungle I also brought you on their annual expedition to the grove where the fruit grows To supply enough actual energy the expedition needs to retrieve a minimum of 50 stars by December 25th Although the elves assure you that the grove has plenty of fruit You decide to grab any food you see along the way just in case So They just won't fly That's a big much, huh? All right, let's see Collect stars by solving puzzles two puzzles. We made available in the calendar The second puzzle unlock when you complete the first each puzzle Each puzzle Grants one star good luck Okay, now for today's task, right? Oh, we gotta be here We went up to like a hundred years. I think at one point last year, but it all starts without one year, right? So, uh The elves take the jungle must be too overgrown and difficult to navigate in vehicles or Or axes from the air the elves expedition traditionally goes on foot as Your boats approach land the elves begin taking inventory of their supplies One important consideration is food in particular the number of calories each elf is carrying Uh, your puzzle input your elves must take turns writing down a number of calories contained by the various meals snacks ration ctc That they brought with them one item per line each elves Operates their own inventory from the previous elves inventory any by a plank line Okay, so they write the following list And then the first elf is carrying food with 1000 2000 3000 a total of 600 calories And so is that then one item then 11 000? Okay, so we're just adding up these numbers. Okay The elves get hungry and need extra snacks. They need to know which elf to ask They'd like to know how many calories are being carried by the elf Carrying the most calories and the example above this is 24 000 Carried by the fourth Find the elf carrying the most calories. How many total calories? Is that elf calorie? All right, so let's grab the example And let's plop it down here uh in Let's see Let's uh add a file Call it um save it this is gonna be example All right, uh now we're gonna say uh So read input is gonna take uh, it's gonna take a string Uh, and then it's gonna give us an IO and it's gonna return a list of lists of hints Okay, uh Read input file name equals and I always forget How to do this every single year Uh, let me see So, uh wait, I can do this right? Yeah, okay, okay, so let's see. Um G8ci are running 9.2 here. Oh, hey, hey little Annie My biggest fan wearing one of your t-shirt t-shirts All right, so I'll say read file. What is the type of that? Uh, so this gives us a string. So let's say do f File it's gonna be read file file name Okay, this one is actually file Yeah I could do file read file file name and then We want to split Oh Thor's hammer Little ante as in bed. Oh, I have to say at that. Yeah, I should also say all these things say I announced it on twitter, but I think um I think I should announce it on on like types dot Oh Fabian is here. Ah, see the gang's all getting together again Okay, let's see. Um, so we read the file name. Uh, okay, and then we do I think this Split that T span Yeah, so this one gives us, um Dark span Yeah, so it returns a tuple wall. The first one is longest prefix of elements that satisfy and uh, oh, let me actually go into settings here Settings And I remember I needed to do this before terminal Uh font, right? And I need to change the font of the terminal Yeah, this is better. So you guys can read it at home All right, uh, wow the Haskell hum is out right okay, so We take a so we have a list of lists So this is going to be just a list, right? Okay, and then Let proc so We are gonna cut it into a list of lists Uh Lists of lists. Let me see This is gonna take a list of strings and go give me a list of list of strings. Okay So a list of lists equals, uh So empty is just gonna be empty list of lists a What am I gonna do this? So I want to take the span, right like kind of in a loop. So I want to do um So so I'm gonna do, um You know span and then equals Uh, no, so this is gonna be not equals space, right? Okay, so let a A elves equals So elves of empty is empty elves of Xs equals Where a x comma y Is equal to span Not equals not equals Of Xs So then this is gonna be the elf and this is gonna be the rest. Okay, so this is gonna be um x elves of y Okay, and then let's just print a Elves of file. So let's just see what this says main Main equals read input a example Okay Now let's see here ghc What do you say? Ah Sad to be not they want to do That would have code, but it's also good to be busy. Hopefully you're doing something more useful Ah, but it's fun. Huh. There's no main module. Ah Oh We didn't open in the AC 22 Day one, there we go. Oh, and we need to return here also We keep doing control x control s, right because I was doing a lot of emails a little bit Huh. Oh, yeah, it's not not equal this way. It's the Okay There we go Uh Let's compile it. Okay Ah, okay, so I need to do Lines of this right, uh, so it's gonna be All right, so else Uh-huh, so it's actually going to be this I think Uh, so this is Yeah, and then span Oh, maybe if it Ends I think like a file Ends in the empty like no See what we're actually getting here Yeah, okay, so we get a little strings and then the empty string as it will return like the first non empty element like this, right? Okay, uh So we'll take the x And then so it ends up with the empty one Of it's probably a better way to do this. I think maybe I'm misunderstanding this So it takes and then returns A tuple, okay And okay. Yeah, so here So now I'm throwing away The element that's yeah. All right. So now we got the list of lists Okay, and then Let's enable That type application. Okay. Now we go ggi and say doc read, right? So what I'm going to do here Is I am going to return map read add int Okay, I'm going to map over the files of else Else file we got it. Uh, let's see what we get here Didi didi Uh, all right And okay So now we have the input in a nice way. Okay so, um They'd like to ask how many calories are being carried by the of carrying the most calories Okay, so, uh prob one Takes a list list of aint's and returns an int So we do prob one equals so Cals equals we're going to map some Over read and then we're going to say Okay, let's just say that Uh Print up problem one. I think it's not good. Yeah. All right 24,000 right So let's get our puzzle input Get a new file paste it save it load it um And then we change this to be input six seven zero two seven I should not print the file Okay, let's uh paste it All right We got part one Let's actually not run it just like this just actually do it. You know, that's user being Okay, wait, can I make time give me like milliseconds? uh user been time Milliseconds Uh Takes a zero point zero one seconds 10 seconds All right. Now, let's do problem two. Lanny has so many like annotations um Yeah, let's see By the time you calculate the answer to the health questions They already less than the health countering the most calories a food might eventually run out of snacks Uh, the little carriage you carry by top three l Carrying the most calories that way even if one of those Throw up three on the fourth elf the third elf and then the fifth elf okay Now let's uh Just copy this in here Now, um example Let me write problem two. So now we're just gonna Uh map some and then sort And then take three And then we're gonna solve a moment. What are you talking about data kinds here illegal type? Why is sort not in the prelude anymore? Okay 45,000 we get for the example now. Let's do it for the input. Let's say 9729 All right, we did day one Thanks for tuning in. Uh, it's a short one today mostly, uh Yeah, I was just setting things up seeing if they worked. I figured out two things number one I need uh to fix my uh keyboard can Uh, so it it works, but it's freezing So I need to do something about that Uh, and then Yeah, I need to uh because I have like a chat view here, but I need to make it More zoomed in. I think I need to go to like twitch Uh Let me see if I could just figure this out now because I have you here and then You can send a message You can Think of me then we've got Babu yet to cry wada punk us Uh I want to go to channel Let me pause and there's like that Where's that interface for the studio creator dashboard Yes, that's the one Okay, now I'm gonna take my chat and I'm gonna pop it out Okay, yeah, and now it is actually huge Ah, now I can read and now I can look at you guys in the eyes Uh, and I can see what you're seeing. Let me just say something here. Hey, oh Wow Amazing stuff. No, this is uh because I got my I have my setup right so I got my teleprompter All right, so that was it for today Uh quick and easy, right? Not much happening, but Thanks for tuning in and uh, yeah, I'll see you same time tomorrow six o'clock um And uh, yeah Yeah, we we're doing this we're doing it this year All right, thank you for tuning in again and uh catch you tomorrow Bye-bye decision. All right