 hello all and welcome to advent of code day 7 2022 we've been at it for a week now and we've done okay so far I think we've done a lot of parsing I mean we've been trying to be principled but you know sometimes it's just easier to just work with a streamer as always we're doing it in Haskell because it is the best programming language and I just want to point out that at this page right it says lambda wide dot 2022 and ah refs right they write a lot of OCaml and they always show up to ICFP they're apparently sponsoring advent of code this year so we're not alone out there I should but should have been I've been sometimes wearing hrefs t-shirts he got the ones with the camel but this time I have a tie-dye shirt made by a 90 my biggest fan but it has green in it so I put a little green square behind my back to make the colors work out hope you don't mind the hack anyway how's everyone doing today let's take a look day 7 ah yeah we're still working with this device they gave us a communication device last time now we're trying to see what we could do with it by the way Dwarf Fortress came out yesterday we haven't played it it is a legendary game you should check it up huh yeah try to raise me but I'm chatting about it at the same time so it's not quite a race but yeah alright so let's see the race has started but I think we should get started right okay so what are we supposed to do you can hear birds chirping and rain doesn't even leave to the efficient proceeds occasionally you can even hear much louder sounds in the distance how big do the animals get out there and wow this isn't some altered lore reality I wonder if someone does like a in-depth Lord Lord dive of the advent of code anyway so we fixed the communication device you found a startup message before but now I'm trying to run a system update okay no space left okay this is a classic perhaps you can delete some space for the update you rather advise me situation and say they're very salty term you're possibly put for example see LS okay and then some numbers dirty CD ALS 3 okay so here we really have to parse the input like we have to we have to model the system dirt a so LS ah okay so it's just running LS I'm just printing today okay well files is the case is a tree of files plain data and directories which can contain other directors or files the outermost directory is called root you can navigate around the file system moving into our directories and listening content that they're currently in within the term level lines of beginning with dollar or commands you executed we're much like some modern computers city means change to a tree as city dot x means we'll move in one level to your dollar so just a guarantee of the boot husband's list okay wow yes so we have the file system these directors also contain files of various sizes the distance well if first of all we shall be fine to find a director a good candidate for deletion to do this need to determine the total size of each directory total size of a director is a sum of the type of the files it contains directly or indirectly directories themselves do not try this having interests okay so we have a size yep and a directory has a total as the other most your director decided for us till the size is 48381165 the sum of size to begin find all the directories with a total size of at most 100,000 in Calculus other total sizes in the example is a great piece of those ideas 9 5 4 7 as an example drivers can count files more than once yes find all of the directories with total size of at most 1000 what's the sum of the total sizes of those directors wow yeah I was warned one of my friends was also been doing these and he said like did you did you see today's okay let's say and I talked to Andreas Abel who's a he works on Agda let's paste the example and and he's like yeah you can just hard code things right away but we want to do some parsing okay let's keep the example here and now how are we we're gonna model this as a tree right data data a dirt tree equals data files of dirt tree equals a so it is either a file we actually we don't have to remember the names of the files we don't care about them maybe so maybe it matters later in task just let's not let's say file or it's a deer so it's it's a deer which is a file of a string hint otherwise it's a deer with a name okay so we're just going to we are just going to we're not gonna like keep the sizes of the directories deriving now read input okay so we'll get a list of commands okay and then we're always going to be jumping around okay so let's let's read the input now we need to keep track of the like current path or something okay so let's say find find deer takes in a deer and a string and returns a deer so this is like a zoom we're gonna zoom in okay find a deer and a root and then with a path equals a this is actually so directories either is a list this deer entry now a dirt is either file or a deer and a deer is actually has a string and it's a list of deer entries okay yeah deriving shows a fine deer route path okay so let's see this is deer entry this is deer entry okay path now I'm gonna copy the split function from before we wrote it at some point right what do you remember it just as a chunks function split on yeah so this is gonna be the split on and we're gonna split on the okay let's say let's let's not do that hmm so how are we gonna model it you want to model the directories and then we're kind of so this is really hard right we first have to build up the directory and then we have to because we're not just giving the territory that one then it would be easier like we actually have to kind of so it looks like they're doing like a okay let's let's see here so their size is going to be a deer entry to in now their size of a file I is just the file their size of a deer and entries equals some map their size entries okay so this is how the size of the directory now okay let me just check the input I'm sure yeah so they both start at the yeah so they always go kind of doing like a depth-first population of it right okay so let's see so we have a so let's when we're populating this okay we have the deer size populate takes in the list of they're just gonna have a list of line list of string we're gonna return a deer entry which can be the root populate so if you have a color CDR then we just so this is the first one okay now this one is going to be a equals deer entries where okay so this is going we're gonna say the root it's deer entries so we're gonna say let entries is equal to populate are this is really not done in a convenient like the ink like this is also like I feel like this is a really a theme this year right like the the problem is not really the problem it's problem is just causing the thing okay so this is actually gonna be so always to CD and then LS CD and then CD and then so it was CDA and I'm into CDE so we so we're always okay so from CDE and LS and then if there's no directory there so we're always gonna have so we're gonna split these into chunks of a of matching so we're gonna match CD dollar and a CD doc doc right at the end right or all of them except the start because see we see here CDA and then we go into E and then we go return from a here okay so let's see so only that only that this only the root is special okay so populate it's okay so we're gonna we're just gonna skip the first one okay and then we're gonna say so first one is gonna be CD dollar and then it's gonna be dollar LS okay and then the rest okay now okay so let's see here let's see populate dear okay so this one is gonna take a list of things it starts with a CD and then this one starts with a CD and then let's see but you get what I mean right we're gonna like find the CDA and then we're gonna take until at the end of that so because we want to you want to you know conquer and divide right okay so it was way easy if it were in prefecture right we could just take until okay let me see hmm okay populate dear so this is a line and then imps okay this one is populate dear is gonna give us the commands okay and then we're gonna return a deer and tree and we're also gonna return the rest of the commands okay now populate dear Ellen are a so we're gonna first of all take from the start of the Ellen so that's going to be how do I like match against a just partial string okay let's say here dollar CD and then space and then your name gonna be span no this is not gonna be span yeah this is gonna be split at Ling CD dollar CD space okay and this is actually this is always gonna match right otherwise equals error wasn't a deer okay now this is gonna be okay so we're gonna we're gonna take while we get a take okay this deer okay so this would be really good we had like a parser like a like a multi-line parser let's see a text dot parser commentator dot read be okay and let's see let's see here okay so this is gonna be a it's actually gonna be like a tree data a deer tree sorry I'm going back and forth here right it's just gonna be a string and then a list of trees okay so we're gonna kind of encapsulate all the commands in that tree okay data tree what is wrong with this ah I just need to do DT and then it's gonna be the string and then list of the rest of the trees deriving show okay actually don't want to rush up but we're gonna do I didn't you know okay so instant instance read gear tree reads crack prior equals read P to read P to Prec is that a thing we'll go read P to Prec ah parser combiners okay so ah okay I can just do a reach Prec it's actually just lift dot ours and then read P to Prec now wait a oh yeah read Prec to P lift dot Paris a sorry so I'm defining the read s here right now this is read P and I want to say a read Prec to S read Prec to S S parse let's import import tags dot parser combiners dot a the type of this parse then has to be read Prec dirt tree but it's not gonna be read Prec it's going to be a a read S now read P yeah it's gonna be a dollar lift parse and then this read P is gonna be where parse equals okay so now we have to produce one of these dirt trees and we're actually so and we get in the so what if you use tags dot our parser combiners what if you use parsec oh but this is in the parsing module okay let's just say here okay so parse so we're gonna have like between open close parsers open followed by P and finally close okay so then we do um so we're first gonna parse a string right we're gonna parse a root it's gonna be a string a dollar cd slash and then slash right return undefined import tags dot parser combiners that read P okay so we're gonna first take this cdn and then a let's see a let's see and then we're gonna do this we can we actually don't care about this then we're gonna say here at trace and show m array we're gonna import debug dot trace and then why isn't it what is wrong with this could you parse it uh or uh let's actually be careful here okay now a so read input takes in the file path and returns a dirt tree read input fn equals a we're just gonna say read at dirt tree dot read file allen now we need to say this to be language gc2021 actually and it doesn't like this because we haven't fmap and we're not doing io and this is actually supposed to be fmap okay now let's do here do read input example print now we're just gonna see where we're at right let's see a cd day seven gto day seven day seven dot hs and user bin time day seven okay so yeah okay so we took the first string all right okay now um okay so now it's gonna say okay so then it's gonna say uh it's actually gonna say um string ls dollar ls okay we print again okay then uh and then slash n right okay now it's we're gonna say a like take while right um many so let's say many one uh and then we're gonna say a many one a parse command now we're gonna say here a parse command uh parse this is actually parse ls okay parse ls a equal to do so uh let's not actually take this ls let's say many what no it's actually gonna be a let's say let's actually have this be a ls a ls rise okay parse ls it's gonna be do we gonna we're gonna take a string dollar ls and then a a we're gonna say a lines a dear cons equals a many one uh and we are gonna we're gonna we're gonna uh we're gonna take let's say many it's gonna be many one a oh we can't hear you hello you can't hear me at all because my stream says it does say that uh it does say that i'm broadcasting and let me see not at all question mark stream says i'm broadcasting though okay let me look into these technical issues sorry about that a twitch.tv yeah i mean so what i'm seeing is a let me see here so the audio levels here say this is going to be very confusing but the audio levels here say that wavelength stream is being broadcast okay now advanced audio properties and it says it's broadcasting the stream one and the stream one is going up okay let me see because i can definitely hear myself but i cannot hear this is broadcasting okay and what am i doing differently today oh this is not the one one two three four five six one two three four five six okay is it just because i'm on my own channel or does it not say okay let me restart the stream uh okay all right sorry about that now let's go back and restart the stream okay and i restarted the stream okay and i restarted the stream okay and now i can hear i restarted the stream okay okay and now i can hear i restarted the stream sorry about that and i don't know what happened but so the audio was recorded for part one So it's only recording. So something went wrong between sending the recording to Twitch or sending the actual progress. That's weird. I think we just hit like a... we hit an OBS bug or something. Anyway, sorry about that. I can also see the OBS setup. Anyway, so to recap for those of you on the stream, we're trying to... we have to parse these two things. Let me actually close the example here. Okay, let me just keep it like this so you can see the chat. Also, let me know. Yeah, let me know if it happens again. Sorry about that again. So, now we're trying to say jerk-hunt. Many till... Yeah, okay. So first, just a... parse line is equal to... is just equal to... many till... many till... parse line is going to be many till. So we're going to get and then we're going to say... we're going to say char n. So this is going to be many one... many till... a parse line. And then we're going to say it's many till a char... and we're going to say... this code is going to be parse like a cd dot dot. Oh no, this is going to be... so we're going to parse a line until we get a parse cd. It's going to be... so it's going to be... so now we're parsing a cd line, okay, which is going to be... do a string $cd space. And then a... a... dear name is going to be a... a many till... a char n. And then we are going to return a dear name. So when we're parsing an ls, we take a ls and we're always going to end up at an... no, we always end up on... we don't end up... okay, let me see. Let's see, let's say... let's... so let's just look at this again, okay. So, okay, and then I'm going to say... okay, and I'm going to say here... so we... let me parse a line. Okay, and so if I trace show rest and I trace show m ln. Yes, that was all our ls. So an ls is really... until... so we parse the lines. Okay, so now we're going to press ls. We'll do a... so first it's string $ls. Okay, now I'm going to say a ln. Dear cons is going to be many till. We're going to parse all the lines. Parse all the parts. We're going to parse the lines. Let me think it a bit smaller. We're going to parse lines until we parse a... a... parse cmd is equal to many till yet. So many... so this is the part of command. We actually do a char $. I do actually... char actually... let me see. So it's char and then a many till... So many till parse line parse cmd. Okay, a turn... So we actually just do here dear cons. Okay, so now I'm going to say here parse ls and then take a look at the rest and then trace show m ls res. Let's actually print that out. I think this works. Yeah, see? And we got the... We got the contents of that directory. And the rest... Okay, it seems like it throws out the... Yeah, so it actually pars cmd. So it throws out the parse ls. So it's actually... it throws out the... Oh, hey woodpecker. Thanks for the follow. And... okay, so it... But how can I kind of... I want a many till until n succeeds. And then so it... It... So it reads until the end. But then it doesn't return that character, right? So it doesn't return the command, the next command. Okay, let's then see here... Okay, so let's see here. Maybe we can say here parse many till get char parse cmd. Let's see until... No, so I want to... I want to get the value at end here. Right? Because I don't want to... Part zero more kind of by one. Separate it into... Okay, I don't want to... I'm doing day seven of the one. But we're trying to... We're doing it with a parser. We're trying to write the parser to parse the thing into... Into a directory. And... Okay, okay. So I want to say here. So this... I want to... So parse... Okay, so this is going to be look cmd. Look cmd is going to be a... Okay, so I'm going to look. So I don't want to consume it, right? Look ahead. Returns a part of the input that is left without consuming it. We have to be careful here. Okay, so we're going to just say look cmd is going to be... R is good to look. Ah. Oh, maybe I can just do like this. Do. So I want to say rest is look. And then I'm going to... I'm not going to parse a line. I'm going to say... We're going to say a f and line. Okay, so then we're going to say rest is going to be... Lines. Okay. Now this is going to be... This rest here is supposed to be a list of strings. Okay. Now rest. Okay, so okay, we're going to say like this. Now if r and then we're just going to say... Okay, so we're actually going to say look cmd. We're going to say... This is going to be a list of strings. So it's going to be... If it starts with the dollar and then we don't care about the rest, we're going to say return true. Okay, so this is going to fail, right? But it's not going to consume anything when it fails. Okay, look cmd. Okay, let's see. Yes, see? Now the parser succeeds, but it doesn't actually consume the input, right? So we still have the cda there, which is exactly what we wanted, right? Okay, many tail parts line look cmd. Okay, so now we parsed on ls. Okay, so... Okay, so we parsed the ls, and now we want to parse a dir. So we do parse dir is going to be... Let's see, no. Pars dir is going to be do. Okay, so we're going to take the... We're going to take the string dollar cd, and then we're going to... So this is going to be get char slash n. Okay, so this is going to be dir name. Okay, and then we're going to say parse... So after we get... After we change the directory, we always do ls, right? So we're going to say ls res is parse ls. Now... Okay, so now we're going to say a... And now we're going to say many tail parts dir. String dollar cd dot dot slash n. Okay, so dirres... Now we're going to say return dt. And let's have this in here. Okay, we're going to say the ls res is going to be a string. Okay, ls is going to be a string. And then a... Yes, so it's going to be the name. Okay, so we're going to say dt. Uh, dt is going to be the dir name, which is a string. It's going to be the ls res, which is a string. Oh, that's a list of strings. Yes, okay. The ls res here. And then the res is going to be dirres. Okay, now... So we do cd slash and then parse ls. Okay, then we say look. And then a... So now I'm going to say here... I'm going to say a... Da is going to be parse dir. And then we're going to say trace show m da. Okay, let's see what happens now. This might just fail. Huh. See? And it's nested. So it goes a and then e. So it finds dir a, right? And then it goes into e and then it finds this one and it ends the parse of e. And then it ends the parts of this. Ah! The beauty of proper parsing, huh? Okay, so ls is going to be a parse ls, many to parse line. And okay, we don't actually care about the... Yeah, okay. So now we've got the a... Okay, but now... Okay, so we have a special case for cd slash. Okay, so this is going to be a parse dir. It's going to be... It's actually going to be parse. It's going to be going to be cd slash slash. Or it's going to be euf, right? So this is the euf. So this is going to be a choice between this one and euf. Which is the euf view, yeah? Ah! But it doesn't have the same type. So let's just do a void. So this is a function data.void. Which just takes things and returns them. Okay. And like kind of ignores the import control.void. And then these have the same type. And the problem with this one is that this one has a... Ah! So choice, read a... Okay, these are the match. So the string here, maybe just void then? No ls map? Yeah. Okay, this one parses, okay? So now we're not going to do parse ls and all this. So we are just going to do parse dir here. Let's see. Oh no. Okay. And the problem with parse dir now... Okay, let's actually see if it just does the first thing. So what is the problem here? Okay, a parse because it should... So parse is A correctly. Okay. And now let's say... Now let's take a look at the... Okay, after we parse the A. Okay. So then the rest is CDD. And then we parse D. Ah! Okay. CDD. And then we parse... We get till... We get the dir name. And then we get the ls res. Let's see what happens here. Ah! Okay. So this one has to be probably a... Let's actually just see what happens here. Let's just parse dir. So we're CD and then we do... So we do CDA. And then we do dres. Let's show the... Okay. Now let's see what's there after that parse, okay? So we show the rest. Okay. And we just parsed and... We didn't get anything. Yeah. So this is the... So ease was parsed. Okay. And we did parse A. But then... And then CDD is there. Manitill parsed there. Okay. Right. So we start by taking the dir name and the ls. Okay. And then we're left with this. Okay. And then we start taking the command and the ls. And then we... And then we are... So we have the ls. And then we're left with this. Okay. So we go into there. And then we're left with this. Okay. So this one closes the... This one. And then this one closes the... And it closes this one. And then we go into d. Okay. And this is CDD. Okay. And now we take the CDD. Okay. So we got the dir A. And I feel like now it's trying to parse CDD ls. And then... Okay. Maybe Manitill also tries to parse dir. And then if it gets... It's getting CD.added ends. If it gets the oaf it ends. I like some nested directories. Okay. So let's... I don't know how quite how to fix this. So I'm just going to have a special case for the CDD. Because it doesn't conform to the pattern. Kind of. Okay. Then we get the ls res. Okay. And then I'm going to see a parse ls. Manitill parse lines. Okay. Let's do lines. Luller a... We have lines or parse ls. Expected repeat. So this is going to be parse ls. Right. Okay. This is just going to be parse ls. That's the lines. And then we're going to say a... How many a filter... So let's say here. So l and take... Take a three of l and equals equals here. L as a res. Let a root subs equals... So we want to say a length of this. Okay. So we do ls and then we parse there. And then we parse there. Okay. And then we'll just say a repeat. No. Replicate m. So then we're going to do something n times. So we're just going to say a num root subs is going to be a... So we're going to say root dares is going to be a replicate m subs. Part of the dare. And we need to import replicate m. And we're not actually using this dare entry anymore. Okay. Replicate m. Yes. Now. And how do we refine this? So it's a return. We are going to say dt of slash. And we're going to say the ls res. And then we're going to say root dares. Okay. Let's say here trace show m root dares. Maybe it fails before that. Yeah. Trace show m num root subs. Okay. Because it finishes with the cdd. Okay. Let's say d a is far as dare. And then I want to say a rest is look. And I want to see the rest here. And we're going to say return undefined. Ah. Kill the terminal. Sorry about that. And do do do do do do do do do do do do do do do do do do do do do. Linking. Okay. So this is what's left. Okay. So what I don't get. Okay. So we're here. Okay. Let me see. Trace show dare name. Trace show m dare name. And then trace show m ls res. Okay. Trace show m. So then let's cdd. cdd a slash n. It's in the ls res that it doesn't like it. Okay. Okay. Yeah. It's because it's it's not it's not actually choice a look command or EOF. So that's what's the problem. Many to get charged here. So far as the ls right. We managed to get that far I think. And it says D and then it's saying these three things. And then it says many till far as line. And now it's saying look command or EOF. Okay. Maybe up because it's probably not getting the EOF character. Right. It's getting the empty cdd. Let's see empty rest empty equals do empty list out of look return. Okay. So this is rest empty. Okay. It but so it's getting that. Let me just see res. Trace show em res a return res. Do I actually get the res there? No. So the problem is some are here. Okay. And many till get charged slash and if I just end and add a new line there. Oh yeah. Okay. So it's because it doesn't end in a new line but does this work with EOF also. Yeah. It also works with you. So the problem was not the rest empty here. It was a okay. The problem with this many till get as a choice a char and you have. Okay. Now I think this can just be rewritten as parsed here. Ah. All right. We managed to parse the file system. That took a while. Okay. Now let's say let's let's say okay. So now we parse this input. Oh wait. I did it just parsed because I added this new line here. No. Yeah. Okay. Now it works. Okay. Parse line instance read. All right. Not bad. We managed to parse it. Okay. So let's remove all these trace and looks. If I add a bit. Yeah. Okay. So now back to the problem. My god. Let's actually I just want to make sure it actually parses the input also input. We don't want to always work and then figure out that it does actually work for the input. Okay. Read input input. Great. All right. It parses the input as well. The parser works. Now problem at hand is okay. Now let's say dirt tree. Let's say this is dirt tree string. All right. And this is dirt tree string dirt tree string dirty string dirt tree string. And we're reading at dirt tree string. Now data dirt tree is going to be a function. So it's going to be DT. Okay. So that's going to be a dirt which has a string and string and has a string and has a size. And then it has a let's call this FS. Right. So our dirt tree. Okay dirt tree. Okay. Actually just a dirt. FS entry. We call it. Okay. So this is going to be a dirt tree and then a list of FS entries. Or it's going to be a file string int. DRIVING SHOW COMPRADE. Now we want to convert. What is the problem here? Yeah. It's probably because I already defined it here. Okay. Dirt tree string. All right. This is just a dirt tree string. Let's just see if this still works. Yeah. Let's comment out there. Well, let's comment out the region boot here. Now we want to say Friday function to FS is going to be a take a dirt tree string and it's going to convert it to an FS entry to FS. Okay. So how did they dirt tree string? Look, let's go back up. Okay. To FS. Okay. So we have the DT and we have the. So these are all the directories only. Right. So D name. We have the LS res. And we have the subjairs. Okay. And we are going to say, okay. So this is going to be a dirt and then the D name. Okay. And then we're going to have the D size. Size. And we're going to have entries. Okay. Where? So now we're going to parse the LS res. Okay. Okay. So let's say here. So we have to parse the LS res. Okay. So we're just going to take the LS res. We're going to throw away all the. We're just going to take the files. Okay. Files equals filter. Prefect. Can I say prefix? No. Stir. Okay. So take three stir. Let's see here. To file a string, maybe FS entry. Okay. Now to file. Okay. So if it's a string and it starts with D. I R whatever. Then it's it's going to be nothing. Otherwise to file it starts with a number. F Aster. Okay. So it's going to be a span is digit. Right. Where? So it's going to be a FS comma and then an FN. Equal span is digit. This is going to be from data.char. What shortcut that was? I don't want to say this. Day six. So this is going to be span is digit. Now we're going to say import data.char is dig it. Can I dig it? Now we're going to say this is going to be file. And that's going to be FN. And it's going to be read at int. It's going to be just this. Okay. Just and we're going to read it at FS. Now span is digit stir. Okay. Now we're going to say here a now. Okay. Where where files equal map. Maybe to file a LS rise. Okay. This is from import data dot maybe map maybe. Okay. This is going to be the files. And then we're going to say a we're going to say a subters. FS subters is going to be map to FS a subters. Okay. And then we are going to say that this is going to be the entries. Right. Map to FS subters. So this is going to be FS subters. Now this size is going to be equal to let's see. FS size is going to take a FS entry and give us an int. And FS size a file whatever s is equal to s and FS size of there and whatever s equals s. Okay. Now this size is going to be a it's going to be some a map FS size to the files plus FS subters. And we can actually do this because they are both FS entries. Dear dename desize FS subters a yeah. This is going to be actually this is going to be actually files plus FS subters. Now let's see here a to FS. Non-exhaustive patterns in FS on this dash f in. Huh. Right. This is actually right. Break a span. I think this is going to be a break. And then we're going to say space here. Right. What is a trace show it trace show it. Now we saw an important thing about trace debug dot trace. Let's see. Okay. Why is it empty here to file string up to file. This is like the empty command in the beginning. Let's see here. Now span. I think they should work. Huh. Okay. See now we are there and we got the total size and then file B. The file says B files is C and A is this. Yeah. See. Okay. It just works. Now does it work for the input. Yes. Okay. So now we've we've done the parsing part. Let's say let's do the you know we could do the pretty printing to print it like this. Oh let's just do that. Right. Instance show FS. Oh no. Okay. Let's say let's say let's see. Let's see. So A doesn't have the size of A right. So to create a line nine four eight five three. Yes. Okay. Now now we have to let's see. Let's see if we can write the show here. I think it would be nice to just show it in a nice way. Okay. We're trying to do a show for this. Okay. So let's not driving show. Instance show FS entry. Where? Okay. And now so show of a dare and dename int entries. This is going to be equal to let's just see how here. Okay. So it's going to be a it's going to be a ash and then plus plus a plus plus a dename plus plus a this string a dear size equals same as for the files. Right. Plus plus show a as this is not int. It's going to be as said a show as said a plus plus close the braces. Okay. We show the deer and the size of it. And then for all the and then we're going to say where a sd sub sub dares so a cons equals a map show entries. And then we're going to say a we're going to we're going to we now we have the lines and then we're going to map and we're going to add two spaces to the front of all of them. And then we're going to we're going to unlines that. Okay. And then it's going to be this and then it's going to be. Okay. So this is a slash n plus plus cons. Okay. This I will show a directory and I'll show a file fn ss as said equals a dash plus plus f name plus plus file comma size equals plus plus shows as said plus plus. Now let's see how it printed out. Oh yeah. I derived show but now I'm redefining show. Okay. And this is not it's going to be fn. Wow. Okay. Didn't quite work as I invited a deer. Okay. And then it prints the directory. Okay. First of all we need a we're missing space here. Okay. So it printed the d name and then it prints the deer the a deer. So it works for the first one and it adds two spaces in front of all the first ones. So for when it prints a why is it not adding two spaces in front of all the things that are in a it's adding two spaces map show entries and these are all because they're not lines anymore. Okay. So we actually show and we then okay map show entries. Okay. Let me see. Now let me see here. So we do we do on lines and then we do lines again. So we kind of the ones who are on lines dollar map plus plus dollar lines. So we got to kind of undo it and do it again. Yeah. Here we go. You know we get a bunch of extra lines here. But that's okay. Anyway, we got the size here trace show. Where are we showing it? We're still showing the stream here. Okay. But this is this is what we expected. Yeah. Except there's more. Yeah. There's some more spaces. That's okay. Okay. Use them then a and then okay. So but it's not like it's showing the files first. And then okay. But that's fine. That is absolutely fine. Find all of the deers with total size of at most 100,000. Then calculate the sum of their total sizes. Okay. Okay. Let's see here. Task one is going to take in this fs entry. Right. And it's going to give us an int. Task one. We're actually going to start. We know it's a deer. Right. And what do they look like? We have the deer string int and then a list of fs entries. String. We don't care about the name. We care about the size. And entries. Okay. And then we say a so case size is greater than equal to 100,000 of at most. Yeah. Okay. So that's greater than equal thousand. So if size is less than 100,000, then we just return zero. Right. We don't have to recurse. Right. Okay. If size. Otherwise, we say a size plus a sum dollar map. Task one entries. And task one for anything else is zero. Okay. Now let's see here. Print to fs print a task one dot two fs. What do you get for the example? 73314807. To begin, find all of the orders without minus 100. For example, these are clearly some size 954. So I see three same. Ah. Right. Okay. So, okay. This is the opposite actually. Okay. So, okay. It's if it's a Selenium, we just do this sum. Map task one entries. Otherwise, we don't include them if they're bigger than 100,000. 95437. Okay. Which is exactly the one we should put together the example. Now let's do it for the input 179 and then 2222. All right. We got task one. Wow. This is taking us an hour and a half. There was a lot of parsing. Ah. Okay. The total space available is 7 million. This is not, this is 70 millions. To run the update into your new space for at least 30 millions. Yeah. You don't find a directory you can delete that will find free enough enough space to run the update. Any example about total size of the outermost directory and that's the only one new space is 48. Well, this means that the size of the unused space currently must be 216. Okay. Which isn't quite ready. Okay. Therefore, okay. You'll follow actually A, B, A, D, or slash. Okay. Okay. Between these choose the smallest increasing unused space by 24 find the smallest directory that if deleted would free up enough space on the file system to run the update. Okay. Then let's say let's just flatten these. Okay. Flatten takes an FS entry and returns a list of FS entries. Flatten a file. So I don't care. So if it's a jir, now I always forget. So it's a jir string int FS entry a string int. And so this is going to be D add there and then whatever and then entries equals a D and then flatten entries concat map flatten entries. A flatten anything else is going to be the end to list. Now let's see here if we if we if we flatten if we just okay. So we flatten the print flatten not to FS. Now we flatten the example. Oh yeah. Okay. So we get D and then we get E and we get a so then we get okay. And then let's actually just make this a string comma int. So it's going to be a N comma I and then we say N comma I and then flatten the rest. Yeah. So slash a D. Okay. Okay. And then we so we need to we need to find something that's bigger than this number a so task two is equal to FS entry and then a int. Okay. Task two equals okay. So we're going to flatten. So it's going to be root. We're going to flatten the root. Actually we're going to we're going to so we're going to flatten the root. Okay. Then we're going to filter a and we're going to say S and D. So the second part of that is going to have to be a larger or equal to this number 30 000 000. Okay. I think this will work dot S and D. And then we're going to say a minimum by S and D. And then we're going to say a S and D. And this minimum by a should be somewhere a in the standard list a minimum by minimum by a data list. Yes. Import data at least a minimum by a takes in a so the minimum on a minimum by and then I think we can say like on import data dot function on a and we say a we actually say here compare on we compare the second elements. Okay. It doesn't like this because a what's the type of this whole a string command on the pool. Yeah. Okay. So S and D now this is going to be give us a given an int to okay and I'm going to say bigger than larger to 30 but it's based on the size of the it's based on the size of the file system right. So we actually have to say here root at. Okay. So we're going to say dollar we're going to say dollar and we're going to say dollar I'm going to say root and we are going to say that this is the deer it has some isn't the name root and the size of the root is something and we don't care about the rest. And this is actually not going to be 30 million it's going to be 70 million minus a size. Let's see. Ask to I should say this is D. Now let's see what it says for the input. Let's check it. It's not around your answers too high. Here's that make you can ask. Okay. No. Okay. So let's just flatten it then and see something wrong here. A Latin okay and the size of the root is okay this one. So so the total is okay. I think I think we over complicated this part. I think we just over complicated so it doesn't actually depend on the size of the root. Let's just say okay a task to but now it's not giving the right answer for the no it's not giving the right answer for this one. Okay. To run the update you need unused space for at least 30 million. You need to find a territory that you will give up. Okay. Okay. Yeah. So it's actually going to be I think 30. Okay. So let's see. Let's let's calculate this record size record where record size equals there for the application requires a total size of at least 8381165. Okay. So let's see unused equals 7123 minus size. This is how much memory is unused. So that is this number which isn't quite enough. Okay. And then we need to say a record size equals 30 minus unused. Right. Okay. Now I at least get the right one for the first one. Huh. Okay. We just messed up the sizes I think. All right. We did it. It did take us a while. Oof. Okay. So let's recap. We wrote a parser to parse this whole command thing into a string of trees and stuff. And the parser just looks like this like it gets lines. It like looks for commands and then parses the result of the little ls and then it kind of it starts a parse of a directory and then it goes until the end of the directory and kind of starts new parses of directories within them and then kind of ends them. Right. So it's like parsing, you know, matching parentheses. Right. Except start is a CD into a directory and the end is a CD dot dot or a CD and a file. Right. Uh, which is this part. Right. So we parse a directory until, uh, so we parse a new directories, right? Until we hit the CD dot dot or end of file. Right. And this is like starting new pars and then finish that one. So yeah, but it's all about matching parentheses. Right. And I think a doing that with a proper parser is a really key here. Uh, another thing we had to make sure of is that we, we can't just do until we see a command. We actually have to do a look command, um, which is because otherwise, so what these parsers do is that they, like they consume the input. Right. So once you match with something already consumed it, that's why you have to look. Right. So you have to be careful that I didn't consume too much. All right. So that was the hardest part. Then we had to, uh, then we had to turn these directory things into like a proper file system. And then we took some time to pretty print that. Um, and then finally we did, uh, we calculated, um, these were the ones that were larger than like directories were, uh, the smallest directory that was larger than 100,000. Um, and then we figured out how to do task two, but we, it's originally, we just had 70 million here, which was too much. Like we actually had to figure out the required size, but yeah, it worked out, worked out for the example, but it was not actually, uh, it wasn't actually what we wanted. All right. And that was quite a long, uh, quite a long session, I have to say. But, uh, seven. Good push. Okay. I want to say that, I don't know. I feel like I would like more, uh, problems that have to do with the problem itself. Right. And kind of making that fast, uh, making a data structure makes a problem fast, right. Because, uh, what's happened so far is that, uh, like almost all the time we spent, like except for yesterday, I think we've always spent a lot more on the parsing than we have on the actual problem. But, uh, yeah. That's how it is sometimes. All right. Sorry for the audio issues, uh, in the beginning, uh, I don't know what happened there because the recording I have, like the local recording has the audio. But, uh, yeah, apparently the audio wasn't being sent to Twitch, but we fixed that. Uh, and now I have to do some work to merge the two things and then I'll upload it to YouTube. Uh, you can check the playlist. I think it's below for, uh, the videos so far, but I think, yeah, we had a lot of fun. And I, I really liked that we kind of started doing parsing, I think yesterday, uh, like proper parsing with a READP. Ah, no, we actually did it. Yeah, we did it for day five. But that really came in handy today, right? That we were kind of fresh in how to parse things, right? Um, and, uh, yeah, I don't know how people are doing this in other languages, right? Because parsing is, I mean, Haskell is really good at parsing. You just do a monad, you just lazily evaluate. Anyway, we managed quite well, uh, after some initial difficulties. Anyway, thank you for tuning in today. Uh, tune back in tomorrow, six o'clock European time, five o'clock UTC, which is Icelandic time. And, uh, yeah, now I'm going to go take a break. This was a long session. All right, thank you all. And, uh, hopefully see you tomorrow. And yeah, we have a Discord as well, but like there's no one on Discord. But it'll be nice if people want to chat and get some help. Maybe with their editor code. Ah, now I want to ask that, uh, uh, Rahic, right? So he said that he would race me or they would race me. Did I win? Are they even watching still? I'm not sure. We did take a long time, but, you know, I think we still did okay. All right, that's it for today. Thank you all. And, uh, yeah, hopefully see you tomorrow. Okay, bye-bye.