 All right, welcome to the double feature, advent of code. We're doing day 10 and day 11 today, because there was no stream yesterday. We're doing it in Haskell, and we're trying to show that, you know, we can do whatever the rust people can. Just kidding. They're cool, but who cares about borrowing, am I right? Anyway, let's get started on today's problem. I've already prepared the editor, but that's it. Let's see. Hey, Soboch, Sobo CJ, Soboch. You still haven't given me a pronunciation grade, so. But always nice to see when people come back, because, you know, that's what I... Because it's not just me solving these things, right? It's us. We're all trying to figure out how to do it, right? And then if I get stuck, you're like, oh, Marty, how you tried doing this? It's kind of fun. All right, so like last time we were navigating these lava tubes, right? And we ended up... How did we end up... What we ended up doing was... We had like these... We just created a neighbors list, and then we found the low points, and then we just kind of worked from there. Worked great. And we found like what areas to avoid in the Christmas tunnels, right? But now we have to do something else. Okay, so we asked the Submarine to determine the best route out of the Deepsea cave, but only by syntax error. Navigation system, online, all of them, all right. All of them. I thought to bring up a copy of the navigation subsystem. The navigation subsystem is made of several lines containing chunks. All right, I think this is going to be a parsing problem, right? Which is... That's what we do best in Haskell, right? All right, there are one or more chunks on each line, and chunks contain zero or more other chunks. Addition chunks are not separated. One pila. What are you saying? Let's see. All right, every chunk... Oh, no. Chunks... Addition chunks are not separated by... If one chunk stops, the next chunk, if any, can immediately start. Okay, every chunk must open and close with one of the four legal pairs of magic characters. Okay. So, yeah, parenthesis, a square parenthesis, curly brackets, a square bracket, curly brackets, and arrow brackets, that's what we're going to use. So, parenthesis as a square bracket. It's more complex without chunks. Okay. Some lines are incomplete, but others are corrupted. Find and discard the corrupted lines first. A corrupted line is one where a character closes with the wrong character. That is, where the character... Where the characters it opens and closes with do not form one of the legal pairs. Okay. Okay. One battery. What are you talking about? Battery. What do you mean by batteries, Hoppo? I missed the... I missed the context. Let's see. Okay. So, we have to parse chunks. Okay. These are expected, but found. Okay. Oh, no. So, it's not enough to calculate, but it's... We have to actually find which one it was. Okay. And let's go. Let's go. Okay. We're not gonna... So, I think if we wrote like a read parser, it would be too much. But... So, we're gonna just do like a stack thing. Stack-based parsing. Okay. Let's just put this into the example. Now. Okay. So, we have the... So, matches char to char. Okay. Matches this one. Should have a matching this one. Right. Matches this one. Yeah. Should be equal to this one. Matches a curly bracket. Should be equal to curly brackets. Oh, no. And matches a pila arrow bracket. Should be equal to arrow bracket. All right. Now, we read the example file. Read input. Going to do the classic file path to... Let's just give it a list of strings first. Read input equals map. Or just lines over read file. Yeah. And it should be IO. And now it's complaining. Oh, yeah. Because I didn't fmap. Okay. Now, let's go. Read input example. Print. Let's just see what it does. I'm gonna go back to the right directory. DHC03-Date10.HS and Date10. We time it like we always do. All right. We got the lines. So we are gonna say... Okay. So we say a check line. Can take a list of... List of cards, right? And it's gonna say maybe charts. This is the first wrong chart. Okay. So check line LN equals... We're just gonna say check line cur... So we empty list and LN. Now, it's a check line prime, right? Where? Check line. So if we have this case, right? So we have an empty here. Let's actually make this maybe chart. Okay. So we have like a... Okay. So we don't actually have to... Oh, nice. Hi Saints. Place things. And you're reading party. Welcome to our channel. Okay. So just... Okay. We can ignore incomplete lines for now. So that doesn't matter. Let's see. So we say here... So we don't care if it's empty. It's just false. Okay. So we have check line and... Hey, KDT8. KD... Let me... I need to zoom in a bit more. Haskell hop. Yeah. Nice. Oh, we got a lot of new people. I hope you're ready for some Haskell action. Okay. And so... Okay. So we have... Okay. Let's... How do we do this? We're defining check line prime here, actually. There's going to be nothing. Okay. So if we are... If we have... Let's see here. Stack. And then we have C... C's. Okay. Case. Matches. So if we're opening... Sorry. We say just a... N is going to be matches C. So if we're getting a new one... Oh, you haven't gone past day four. I mean, they get a bit harder, right? As you go on. Okay. So we just run matches. And if we get a match... Which is to say that we get a just here. So this is kind of the one we're... So we get a match. Then we just add it to the stack, right? Check line prime. N stack S. And then CS. Okay. If we don't get a matches... If it's not... If it's... So... Right. So if it's not opening a new one... Then we say... Then we have to say... Okay. Then we say, okay. If the stack has something on it... Stack and then rest of stack is the stack. And... And... Can we match patterns like this? Comma... Yeah. Okay. We can do S equals equals C. So because we already kind of... Check the match. Then... Then we just continue. Then we pop it off the stack. Check line prime. And then it's a new stack and the rest. Otherwise, we have found the first one that fails. I think so. Let's say... Let's print... Let's print a task one. Right. So it takes in a... So we do actually map and... Print dot task one. Let's see. What is this Haskell hop? I can't... Okay. Not accepted function. Yeah. Okay. This is exactly... Nothing. So we get nothing and nothing. So these are just incomplete. Otherwise, we get a just... So this one is closed with the first wrong one, right? Okay. The remaining five lines are corrupted. So I guess this one is the third line. Yeah. Expect it. This one, but found this one instead. So stop at the first incorrect closing character on each of the corrupted lines. Okay. And then we do define the score. Okay. So we have the charts. Okay. So let's write a score chart again. Score. It takes a chart and returns an int. Okay. Just score. So we have this one. It gives us a... This may be int. So this one gives us just three. Okay. Score. This one gives us just 57. Score. This one gives us just 1197. Okay. 1197. And score. This one gives us just 25137. And score of whatever gives us nothing. Okay. So instead of saying just C here, I am going to say score C. And this is going to return maybe int. And then we get 11973, 573, 25137. Okay. So we are going to say a map maybe task one. And then print. Functor sum dot map maybe we have to import that from... We are importing it from data dot maybe exactly. Now let's see what the first sum is. 26397. Yes. So we get it for the first one. Now let's get the input. No, not a new folder. New file. Input. And get it. Wow. All right. Let's check how long it takes for the input. I think it should be pretty fast. 318009 in five milliseconds. How long is it? We got the first one. It's all working out. Okay. 18 minutes for the first one. So we're doing a double feature, but I'm hoping it won't be longer than two hours because I want to order pizza. All right. Day 10. Now let's go to part two. I mean part one is... If part one is easy, it usually means we did it in a weird way. That means that part two is not good. Okay. Now discard the corrupted lines. Remaining lines are incomplete. Oh, you're only... Incomplete lines don't have any incorrect characters. Instead, they're missing some closing characters at the end. To repair the navigation substance, you just need to figure out the sequence of closing characters that complete all open chunks in the line. Oh, I mean, this is exactly our stack, right? I think this is just our stack. So here we... So here we return just stack. Here we return nothing. Maybe string. So there's going to be a list of characters. Okay. So do, do, do, do. Now we map maybe... And let's see. Let's not print the sum. We haven't scored it yet. But let's just map maybe for the... Oh, no, not for the input. We're not doing it for the example. Okay. So we get the right one for the example, right? That's good. Did you know it's true? Okay. So we found the five incomplete lines. Start with total score five. Then for each character, multiply the total score by five and then increase the total score by the point where you give in for the character in the following table. Okay. So we're just... Now we have to write another function to score it. Just call this score one. Score one. All right. And now we write a score two is going to take in a string. Turn an int. Score two of empty equals... So we actually have to do equals score two prime of zero. We start off with this. Where score two prime curve and empty equals curve. Score two prime curve C. Now let's SC. This is going to be our score chart. So one, two, three, four. Okay. Equals one SC of equals two SC of. So you should technically check whether we're getting... Or like have an exception. Yeah, let's just have an exception. SC equals four SC underscore equals exception. No, it's error. Invalid character. Okay. So we have a CCS. Okay. So we start with the score of zero. Then for each character multiply the total score by five. And then increase the total score by the point value. Okay. It's going to be score two curve times five plus. And let's just make sure plus SCFC. Yes. Score two prime. Okay. Okay. Map score two. So two eight eight nine five seven five five six six one four eight zero seven eight one. Okay. We get the right scores. Okay. Yeah. We're getting like a lot of extra things here. Okay. And then score another one. The winner is found by sorting all of the scores and taking the middle score. Like why are we doing all this? Task two. So let's just do here just going to be a list of scores. A task two. Okay. So we get a task two p. Let's call this task two parts. Okay. Task two is going to take us a list of strings and return us an eight. Okay. So we do a where stirs is equal to map maybe task two p. LNS. Let's say scores is equal to map score two dot map maybe. And then we do a sort. Scores. We have to import data list for that. A map so map maybe so we have what are you complaining about? Let's do head here. This is not going to be correct. But yeah. Okay. Scores is a list of ints. Now a map maybe couldn't move point. Okay. Let's see. A completes equals a map maybe completes strings. Okay. A scores equals. Map score two over completes. And then we sort the scores. And then we like look up the length scores due to read that's like the middle of a sorted list print dot task two to a date nine five seven. Okay. What is the middle score? Let's go. Three milliseconds. All right. We got day two in 28 minutes. Nice. That was not bad. Good thing this is a double feature. Otherwise it would have been quite short today. Let's see what we did. And like yeah. I mean all we did was like we maintained this stack. I don't know. Yeah. That was exactly like the bot chasing. There's no complexity here. We just did the thing. Right. And I don't know. I think I think they knew that this was a easy thing. That's why they made the scoring so weird. Just to make it a bit longer. I don't know. All right. Let's add it. Detain dot HS. Example input. Okay. You commit him and detain. Okay. Now let's. I mean we could go over how I did it. But like yeah. There's nothing. There's no there's nothing crazy going on here. It's just kind of it's like you know either. We have we have a new match. Right. And then we get the kind of the one that closes it. And then we just add that right or. So or we have something on the stack. And the one thing on the stack is the one we expect. Then we just drop it and continue. Otherwise. We have an corrupted line. Right. So that's for task one. Right. Otherwise we don't have that. There's a wrong one. That's what we were expecting. And then it's just done. Okay. For the second one we did it the opposite way. Right. So instead of. Keeping the score. For the corrupted ones we keep the stack. So because we know which ones we're expecting. So I think. I think this was. I think yeah I think this is harder in other languages. I think it's because like it's so easy for us. So like. It's probably not harder. But I think. Because we kind of naturally are drawn towards just keeping the list around in Haskell. The way we solve task one. Kind of made it very easy for us to solve task two because. Kind of the natural way to solve task one kind of gives you the way to solve task two right away. Kind of very easily so so I'm not going to say it's. More difficult but I'm going to say that a. Like the way you would do it without knowing what task two is might. Lead you to do something that's harder to do. But it's harder to say more. I don't know. I haven't done it in other languages. I can't write because now I know how it should work. So it's hard to maybe need to. I can't do it again right to check it. But. Okay. I was task one. And as I usually do. No I'm not going to take a breather. I think we'll just start off with a 10 day 11 right away. Touch day 11.ages but like. So Haskell more naturals and see. Yes. I think so because in C we would have to like maintain. Like an array right now we'd have to. Dynamically grow this array. And also like the. So this is the nice thing here is that it's like it's like I mean so. We're in C we would have to basically implement the linked list. To do this. But we don't have to hear. I think yeah. But like I mean we're also lucky here in that you know even. I mean we take three milliseconds into this. We could probably do it way faster in like rust or C. Because there's less things to worry about. But. Yeah. Module day. No main main. So we call it main because we want to be able to run it from the command line. Putster Ellen. Day 11. Okay. Let's go for day 11. Doon doon doon. It's a shame that like these are created based on. They are created based on. Like time from release it would be nice if we can see. How we how fast we were compared to everyone. Give me one second. Give me give me one second. I'm just going to answer this message. Okay. That was it. Okay. So dumb octopus day 11. You enter a large cabin full of rare bioluminescent dumb octopuses. They seem to not like the Christmas lights on your submarine. So you turn them off for now. We had Christmas lights so far. That was nice. Let's actually also look. It's like this is a nice graphic. This is supposed to be the sea or something. I'm not quite sure because we're in a submarine. We're trying to save the keys because the elves lost the keys or something. All right. See the last one was super easy in Haskell. But now we have a 10 by 10 grid. So we're going to do something with array indexes, which is a lot more annoying in Haskell than in most other languages. Wow. And we're simulating something. Oof. All right. Strap in. This is going to take a while. Okay. Let's just copy and paste this into example. Example day 11. Right away. D, D, D, D, D. Okay. So you enter a large cavern. So each octopuses only greens energy over time and flashes brightly for a moment when his energy is full. Although you're not sure. Maybe you could navigate through the cave without disturbing octopus. If you could predict when the flashes of light will open. Each octopuses has an energy level. Your submarine can remodeling measure the energy level each octopus. Okay. The energy levels vary between 0 and 9. Here, the top of the octopus image. Okay. You can model the energy levels and flashing lights in steps. First, the energy level each octopus each increases by 1. Then, any octopus with an energy level greater than 9 flashes increases the energy level of all adjacent octopuses. See. Okay. Including octopuses that are diagonally adjacent to it. If this causes an octopus to have an energy level greater than 9, it also flashes. This process continues as long as new octopuses keep having their energy level increased beyond 9. Octopuses can only flash at most once per step. Finally, any octopus that flashes during this step will have that energy level set to 0 as it used all of its energy to flash. Okay. So adjacent flashes can cause... Okay. So we have 9. And then all of these flash... An octopus is highly likely to flash during a given step. Okay. After step 10. Okay. So we have a lot of these. After 100 steps. Given the starting and energy level of the unboxers in your cabin, simulate 100 steps. How many total flashes are there after 100 steps? Okay. Let's just look at the output. Oh, it's not that bad. It's going to be the same as the example. Okay. All right. Now we're going to get into some state-based... Let's think about it first. Can we... Can we get away? Can we figure out if there's a loop? There might be a loop, right? So if we see the same state, then we know how many flashes there will be. Okay. Data.state... R... As... Go... State... Lazy... Yeah. Uh... Haskell... Erase... What are they called? State ref... Erase. Something like that. Uh... Yeah. It's like ghc.r and then we have like frozen array. Oh my God. I don't... Never want this on Hack itch, actually. Okay. Um... sd-array is a mutable box non-strict. Um... Let's see. Acuma ray. Doom, doom, doom, doom, doom. Doom, doom, doom. So each step, we just have to figure out whether one will flash or not. Copy this into input. Oh my God. This is going to be such a mess. Let's at least start by reading the array, right? Uh... ReadInput... File... Path... So it's readInput... Map... Uh... ReadAtInt... ReadC... Uh... AtInt... Isn't that like a read... Digit... Just to... Char to int... Digit to int, yeah. Okay. Import... Data.Char... Digit to int... Uh... Map... Okay, so we fmap... Map... Digit... To int.Lines... Overread... File. Dink, dink it. Okay. Um... So we get the... Okay. We have to do map, map, map, map. Okay. Let's just print out a... ReadInput... Uh... Example... Day11... Into... Print. We start by reading the input that's always solid. Okay, we got the input. Now... Um... STArray. So they are like... Uh... They are like... I think they are... They are like more STUnboxedArray. I think it's like UArray. UArray. STUArray. Is that the thing? STUArray. Yes. So this is the... Uh... So mutable array with unboxed elements that can be... Yeah. Okay. Um... How do we create an STUArray? Hmm? Hmm? Hmm? Hmm? So let's say... Let's say simulate. Um... It's going to be an STUArrayS. Now let's say this is going to be an ST. And it's going to return a UArray. Uh... And with the I is the... The index type of the array is uh... Int 8. And the... A element type of an SGP Int 8. Simulate. Equals run STUArray $2. So I will take in the ints... Uh... Int. Now, uh... We create... How do we create an array? Um... We say to... Construct an array from a pair of bounds and a list of... Um... How do we do like two dimensional arrays? Uh... I think we don't... We can't do it. So how about we have it as a... No. Okay. We can also have it as a map. Right? Um... Just a map of indexes. Yeah. Okay. Let's do that. I think it's easier. Uh... Wait a minute. Let me see. So... So we have the... Uh... Right. Uh... 0 to 10. Maybe I can do it like a... Maybe I can do it with a... Do... Okay. What if I just say... Uh... This is not going to be a UArray, right? It's going to be an array of UArrays. And so it's all going to be... It's all going to be a mess. Let's use data.maps. Uh... Module. Data. Yeah. So import data.map as map. Import. Qualified. Data.map of map. So let's ignore this now. Uh... So let's first... Yeah. Let's first create it. Oh, I forgot. Import data.char to get to int. So... Uh... int to map. So you take a list of ints and we return a map of indexes. Uh... to ints. Uh... int to map. int to map. It's going to be... Uh... So we... We zip with... We can zip. Uh... So we... We map. Zip zero over... Uh... We zip zero over mapping. Zip zero. Inp. Inp. Uh... In... Indexed. Uh... And then... No. Okay. So we... We... Actually, we say... Zip with... Okay. So we have the... Uh... The elements. And this is going to be... And then we have the second one. And then zip with... It takes in a function. So it's like the... Uh... The... Uh... Y. And it takes in the... Uh... The array R. And it goes a... Map. Uh... Over the array. And now this one is going to be... The X, comma, V. And it returns a... To tuple. X, comma, Y. Comma, V. Right? Indexed. Uh... Map.fromList. Indexed. And then this is being... And it doesn't like this because... Uh... It could match type with expected type. List of int, int, int. Oh, right. I have to... Okay. First of all, let's just... Let's go through it. Okay. Uh... Indexed. Map. Zip. Zero to input 10. Uh... X indexed. So what is the type of X indexed? Um... The type of X indexed is a... Int, comma, int. Okay. Then we say map. Y indexed. So... Y indexed should be a list of... List of... Int, comma, int. Comma, int. Now we actually want to... Yeah. Now we say map from list. Concat. Indexed. So we want indexed to be... A list of list of int, comma. So... Concat. Y indexed. Okay. This is type checks. Okay. Uh... So... So zip with... It takes zip with a... X indexed. Right. And then this should be F. Where F. And F has the type a... Int. List of... Int, comma... Int. And it should return... A list of... Int, comma... Int, comma, int. This is the type we're going for. F equals undefined. Undefined. Okay. F takes in the Y. And it should take in the R. And it maps over the R. So it takes in the E. And the X, comma, V. And returns... X, comma, Y, comma, V. Over R. So now we should have a map of like 0, 1, 0, 0. Oh. Int... To map. All right. Now we have it... We have it indexed. Okay. Good. Doom, doom, doom, doom, doom, doom, doom, doom. But what if we flip it, right? Because we're not really interested in... We don't really care about their... We just care about their neighbors, right? Um... And then we want to kind of see which ones are 9. And then we hit them... Those neighbors. Okay. So we have a... These. So... So here, for the purpose of this challenge... Everything, like a 5. So the 5 is 4. The 7 and the 2 is the neighbor here. So we say that the... Let's see. Let's just write task 1. Okay. Okay. We say that the nays of an int, comma, int is a list of int, comma, int. The neighbors of x, comma, y filter in range of x plus 1, y, comma, x minus 1, comma, y, comma, a... Now, let's not do it like this. We just do x plus i, comma, y plus j, where it's y, 0 to... So it's minus 1, comma, 0, comma, 1. And j is also from minus 1, comma, 0, comma, 1, where in range x, comma, y is a x larger than 0 and y larger than 0 and x less than... What is the limit? It's 10, right? It's... Yeah. So it's a 10 by 10 grid. x less than 10 and y less than 10. Okay. So now if I say... Let's just do it like a GTI day, 11.hs. Oh, no. What's going on here? Now task 1 doesn't exist anymore. So nays of 0, comma, 0. Oh, just 1, comma, 1. Why is it doing like that? Okay, what if I remove this... What does this list give us? Minus 1, minus 1, minus 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0. These are the six neighbors, right? Yeah. So you should have a good point larger than equal to 0. That was our problem. Okay, let's check. Yeah. Okay. These are the neighbors indeed. Let's check. Thanks, Oscar. It's nice to have chat, right? We're not getting stuck for half an hour on something that simple. So now we know the neighbors. Okay. Right. So what I was saying before is that we don't really care. We don't really care about... We're usually... We're always checking... We're not checking the indexes, right? We're checking the values. So I'm wondering if we can change that somehow. So if I have it like this, it's going to be like that, okay? Can I like collect into a bucket? What if I have a list of A, B, and I have a list of A, B? Okay. And I want a map of A and then list of B. This does not exist. Okay. So I want to... You get what I mean, right? I want... Yeah, that's true. Okay. X, 0, and X. Let's see here. X... Let's call this... I can't do something weird actually. A, B at... So now we're giving this the value, right? All right. Okay. We can't do that. We just have to say C. And then we can do this. A, B equals C. And then we can say X not equal to A and Y not equal to... I don't know. We can't do this actually. We have to say X is not equal like this. A and Y not equal to B. Then we should get the... Just the neighbor, so no... Hmm. Oh, okay. Yeah. And so we don't want these both. Okay. Let's just say filter not equal to C. Why doesn't that work? What does it complain about? It's all right. Yeah. Now we move that one. Exactly. Okay. Yeah. So what I was thinking before, right? So... Because... If I do an example... Day 11... Into task one. And then task one... Right. So because we don't actually care so much about the pairs. We care mostly about the reverse. So I'm wondering if there's like a way for us to flip a map. A map. In a nice way, right? How can we... You know, we want to kind of merge them. Okay. What are we going to do? So this is the Y index. So let's just do here. Not like this. We do... Okay. Let's not actually... This is fine. Okay. We do... Where F... Flip... Pair... Takes an int, comma, int, comma. Int... Int. Or wait. Okay. So I have the... Let's just have this. Okay. As the int, comma, int. Like this. And that's... So this is Y indexed. Okay. Now... We just do... Task 1... Over... This. Okay. But what if I do sort? Import... Port... Data... Data.list. What is it? It sorts... Sorts... Okay. So I think it sorts on the first one. Sort. By... A... Compare... On... S&D. Okay. We're just going to say... Import... Data... Dot... Function... On... Import... A... Port Data.list. Sort by... So we're going to say... A... Sort by... Compare... On... S&D. And then we're going to say... Group by... Equals equals... On... S&D. And I need to... And this is going to be a list of lists. Now what is this group by return? I added too much. Or maybe this one didn't work. What is group by return? Group by is applied to four arguments. Oh, okay. Yeah, I need to... Dollar... Group by... Expected type... Oh, yeah, okay. It doesn't... Yeah, it returns a list of lists. Okay, so we do R... And then we run... Task 1 or this. So these are the ones like that are 1. And then you have the ones that are... 8 and then 9, right? Okay. Let's call this a step. We're taking a list of int comma int. And we return the same. So step equals... It'd be... A curve. So this is going to be group by on sort by compare on second. Where C... Org. So the current one organized is going to be curve. Okay, now we say a map. So C org. And then we say by num takes in a... Map by num. So it's going to take in one of these group lists. And it's going to say, you know, C comma V. It's going to be map. So this is going to return V comma map. Let's just say... And then it's going to say C colon map S and D R S. Okay. And then we map. So by num. And then we say by num equals map by num C org. Okay. The C org is a list of list of int. Okay. By num takes this. Okay. So by nums. Why is it complaining? Could match type. Okay. Yeah. It's because... Right. This should be first. So this is a list of all the ones that have one. All the ones that have two and so on. All the ones that have one. All the ones that have two. Okay. Let's actually just look at it. Right. Let's say here map. Int int comma int. Map.fromList by nums. Let's actually make these sets because we don't care about... It's going to be fine. We don't care about the actual order. Data.set import qualified data.set as set. And this is going to be a map of int to set of int. Now let's throw out this one. And then let's just map int set of int comma int. This is step of a Y index. I think. Yeah. We reload. And then... Okay. So we have the ones. We have the twos. And we have the... Okay. Yeah. So you get what I mean. Right. Okay. One energy per step. Right. And if they gain... Okay. So this is like the structure we're going to be working with. Okay. Let's call this MKMap. MKMap. Okay. So we have the... The energy level of each octopush increases by one. Then any octopush with an energy level greater than nine flashes. Okay. So the energy level here. So all the eights become... Nines. So let's see. We don't actually have to think about that. Just like at the start, all of them are increased by one. Okay. So let's write the step function. So step takes in a map of int set int comma int and it returns how many flashes there were and the next state of the map. Okay. So step mp equals... Okay. So first of all, we're going to say where level eight... E level eight equals mp... So what do you say? Case. mp bang map dot lookup eight. No. We're going to look up nine of just... So if there is any set with nine in them, just two flash because it's greater than nine. Right. So we increase all of them by one. Let's see. Let's have another one here. That's called tiny X. Okay. This is tiny EX. Let's close date 10. Okay. Tiny X. And then let's run this one on a tiny X. So we have the ones and we have the nines. Okay. So now we write a recursive... Okay. So case two flash. Okay. So now we write a flash. This is going to be like some... The set of the ones we want to flash. Okay. We'll keep it as a set. So flash set dot empty. And then we get the kind of the current map where flash. No. This one is going to be actually... So let's look it up. Okay. Let's say where I flash equals map. Mpmap.bang.8. Now the nines. Okay. And then we say flash. And then we say... So this one is going to be case this one of... If there are any, just s. We're going to have an s. Or else we're going to have... We have a set dot empty. Okay. So the first argument for flash is going to be... I flash. Okay. So where? Okay. Flash. Flashed. You see what I'm going here. Okay. So we're going to kind of find the fixed point for the flash set. Okay. Let's see. Count how many times each member is in this set. Let's see. Okay. So for the initial flash, it's just the nines. Okay. Then we do... So the ones that are going to be concatted... Can I... Yeah. Okay. Let's say... Where... And flash is going to be a concat map... Nines on a set dot from list flashed. Set dot to list flash. So set dot to list flash. Okay. Now... So this one flash is going to set... Okay. Okay. So we have the n flashed. Okay. So let's have this also. The current mp. The current mp. So we have the n flash. We get all the neighbors and we get... So we remove the ones that are... So concat map. Set dot... All right. No, but we cannot... We can't... Because it matters. Like if you see two... If you see one flash, right? You know. So this one sees... Yeah. Wow. Let me see. All right. So this one... Okay. Let's see. Let's do a $2 sort of the concat map. And then we add this to the import. And we add this to the import. So the new flash is... Okay. So this is how many times you flash this round. Oh no. What is going on here? Oh my God. My editor just completely... Oh my God. Let me close it and open it again. Don't save. My undo buffer screwed up. Okay. Group comma sort. Hey, Janitin. Yeah. There's a lot of catch up to do. Group dollar sort. Okay. So these are the new flashes. And then we do the classic nums equals a map. So we take that to x comma length of L. This must be add of n flash. So then we have the number of times each one got hit by a flash. This round. Then now... You see this is a lot of... So it's a big mess, right? Because now we know the number of times each one got hit by a flash. Okay. Right. But we do concat map nays. And we're actually going to filter set dot mem not set set dot member memper. Okay. It's okay. We can actually... Yeah. No. Let's filter not set dot flip set not set dot member flip set dot member. And this should be flashed. Because we don't want to count them again if we've seen them before. Right. So these are going to be the new ones that we haven't seen flash before. Okay. So these are the ones currently flashing that we haven't seen flash before. Yeah. Because it's going to be... So we don't count the... So we get the neighbors and we filter out those that are already flashed and we don't care about those. So let me group and we sort and let me get how many times a new one is hit by a flash. Okay. And so that's going to be this one. Okay. So let's let's set this to... Let's actually have this flashed and it's going to be set dot empty. And this is going to be curve flash. So we're going to concatenate curve flash. Okay. So we get the ones that are currently flashing and then we flash and we remove the ones that we've already seen flashed. And we get how many times each one is hit by a flash. Okay. And in the curve flash. Okay. So we want to... Now we need to update all of the indices. Damn. I'm not sure if this is actually the right way to do it. So we have the list of the ones and how many times they get hit by a flash. So how do we know if they will flash this time? So and curve flash. Let's set that over the numbers. Maybe we shouldn't... Maybe we shouldn't flip this here. Okay. Okay. So the new ones that are flashing. Cool. Okay. So we take... Let's just take in the nums. And then we have the filter. We take the nums and then we say that we have the C and we have the... Number of times... Okay. And now we can look up in the curve MP. Curve MP. Look up. So they all got one more. So N9 minus N. Map C set dot member. And why don't you want this? Could match with... Oh, you... Okay. So the type of curve MP here is a... What's the type of flash? Okay. Flash is a type set int comma int. int to a set of int comma int to the kind of the MP. Which is this? I think like, yeah. So we eventually end up with a... We actually want to return... Let's just say underscore here. We return this. Now, what are you complaining about here? Couldn't match type argument. Okay. Yeah. Okay. So set member C. We fmap that over here. Now it's saying couldn't match. Can we do like this? Can we just like literally write like a pattern match here? And just say... Oh my God. Just true. Is JT is just true equals true. Is JT otherwise false? Is JT dollar? Okay. So now we have the ones that crossed this one to flash. Okay. And we wrap this over nums. And we say here set dot to list of map first of this one. Set dot from list, right? Nice. Okay. So we have the new current flash. Okay. So we want to say here. So this is going to be if set dot null and curve flash. If there's no new flashers, then... So we also have to define the end map. Then we're going to return the set dot size of the end map. Else we continue the loop. So we have the incur flash. So it's going to be flash set dot union incur flash. And we're going to have the incur flash. And we are going to have the... Now we just need to compute the end map. Alright. Then we have to add one to everyone in the end map, actually. Map int set int comma int map int set int comma. Add one. I think it's like map monotonic keys or something like that. Map keys. Map keys monotonic. Add one equals MP. Add one equals map.map keys monotonic. Plus one. What is your issue here? Either... Oh well. Okay. So we add the one at the end because we always consider them as like a... Either currently flashing or not. Let's see. End map is going to be... So now we need to kind of reverse them, right? Map tool list. Okay, we do map dot tool list of a curmp. Okay. End map. So we take the map tool list of end map. Where cm equals. And this is undefined. Just so we can see the type of cm. This is a list of int set of ints. Okay. And we do map a... Map a set dot tool list over it. And then it should be... Yeah, a list of ints. And then we kind of... We have to expand it. So we do a map. v le goes to a... So this is going to go to a... Sip. And now wait, let me see. So this one take a look and we're going to map a... A... C. And we're going to say a C comma v to the le. A... Like this. And then this just becomes like a big map. And then this one become like a tuple section. So I don't... Too much. Okay, we can do it. Just to make the blue go away. So this one becomes a... Like this. Tuple sections. Now cm is going to be a... A... The change the bit. This is what we want, no? No. So the list here is a list of a's. Okay, what are we going to do? What are we doing now? Let's see. So what cm is now is a list of ints. Okay. So we want to map. Okay. And we take the v and the list, right? And we do something to that, right? So what's the underscore here? So this list is going to be p and this v is going to be... Oh, okay. Map v. Okay. Yeah. V comma le. That's how it's going to be. That was the issue. This one is not v. It's v comma le. And now it's a list of list of ints. Okay. Then we do concat map. And now it's a list of int, int comma int. Okay. Now we have these nums. Okay. So we say a num map equals map dot from list nums. Okay. Now for each cm in this one, we're going to go up d cm. Up d. Okay. So this is going to be a cohort and a value. Okay. So we are going to say a case a cmap num map of just n is going to be c comma n. Otherwise, it's just c comma v. Okay. This has to be v plus n. Okay. So we do, we have the update function. Okay. So we map up d over cm. Right. No. What? Oh yeah. Then we flip this around. Num map c. Okay. So we map update. Okay. And now we need to kind of undo the things. But we know how to do that because we have the, this one, right? Okay. I'm actually going to just flip them here. Right. So now this is a list of int comma ints. Okay. So we do sort by compare on first group by compare on first. And then we do our, we do, we make this one a function. What, what do we, what can we group by? Oh yeah. Okay. This is going to be equal on first. And then we apply our by num function. Map dot from list dollar map by num. Oh, so that's wrong. Oh yeah. Okay. Because I already flipped it in the by num function. So now it becomes an int set of ints. Exactly. Easy. Fuse concat map map. Yeah. Okay. So we can actually take this function here and we can say dot here. And then we can say period here. And then we can say concat map. Now, how do we, how do we fuse it? How do you want us to fuse this? Oh no. Just too much, right? Can we just do update for after this? No, we want the concatenation first. Exactly. I'm not going to use this. I don't care. I do not care. Okay. So does this one work? Type checks, right? From list for from list for change the type. Oh no. Oh no. It's not, it's not, it's not changing the type. Saying that something wrong. Okay. So we have the 15s and the eight. Okay. And we want them to set it to a zero with a flashing ones. Okay. I'm going to take a two minute break. I'll be right back. Okay. Not quite two minutes. Sorry. Okay. So I mean at first, at least we can see that. First we can see that. Okay. So all of the, so it's, it's losing the length somewhere. Right. Let's see. Where's this end flash? Let's do, let's trace it. Thanks for the sub semi. Nice to get. I think I got 200 followers now. Or sub even. That's pretty crazy. Or maybe it was a, I don't, I don't, what happened? Let me check the, oh, follower. Yeah. I have 200 followers. That's not bad. Okay. So zero, zero got hit. Once in the first one. Which makes sense. Okay. So I think that our nums function is working. The, or the, the end flash. Right. So we're seeing that this one got hit once. This one got hit. Twice. No, sorry. This one got hit once. This one got hit twice. So that's not bad. Okay. And zero dot comma three. This one got hit twice. So zero comma two should have been hit three times. Yeah. Exactly. Okay. So the end flash works. Let's show, see what the num says. Trace show ID. Okay. We reload, we run it again. Zero got zero, zero got hit once. Zero comma one got hit twice. Zero comma two got hit three times. Zero comma three got hit two times. Zero comma four got hit one times. And then, okay. Yeah. So the, the nums are correctly counted. Okay. So, let's see. So the ones that are the new curve flash. That's kind of the one that, that's a bit wonky. How about we just update the, how do, how, how about we just update the map? And then we kind of figure out the, and then we, yeah, let's, let's do that, I think. This one is too crazy, I think. Okay. I have the nums. Okay. And, okay. Let's, let's actually check this one up. So we have the, let's, how, how, how does an end map look? Let's show ID. So two, so four comma four. So three comma four, three, nine, eleven, thirteen, one. Yeah. Okay. So there's something happening in the, in this one, I think. So it's like it's dropping things somewhere. Okay. So let's take a look. So we have the num map. Okay. And the end map is going to be, yeah, we have the map of it. Okay. End map is equal to, so we have the update, the update function is correct. Right. Let's, let's have a look at this one. So let's have a look at it before we do the update trace show ID. Okay. And dollar trace show trace. Okay. Okay. Just to see which one is. Okay. From this. Okay. So zero, zero one, zero comma one, one, zero comma two. Okay. So, yes. I think this one is the correct. And then we look up then, look up C comma V in the num map. Let's see. Okay. So what are the, what is that? So I think only this one should be an end curve flash. Let's just assume this one is correct. So trace show ID. Yeah. So exactly. So two, two is the one in end curve flash. And then there's none of them in end curve flash. Okay. Yeah. So it's a 109 is in end curve flash. Okay. So sort by group by. Let's see. Where are we losing them? So this is saying zero zero is two and then three and then four and then three. Two and then three and then four. Two and then three and then four and then three and then four. Yeah. This is, and this is before we add one. I think this one is correct. So I think it's a binom function that's doing something wrong. So let's, let's just use that just here. And then what was the type at this point? So these are the ones with two and three and then, oh, because we want to compare on second. That was the problem. So we get three and then four and then five, three and then four and then five. And then of course we get the, so add one and then clear flashed flashed. And we're so clear flashed. Okay. And so then we just clear flashed flash. Okay. That doesn't really matter. We just have to take out the keys that are larger than nine. Let's see. But that, it doesn't really make sense. So there are one that has 10 and then there is a 13 and then 15. So there should be, so there should be like nine that flashed, right? I think it's like the, okay. So we start, let me see. Okay. We're also not doing, we're doing something incorrect. So we add one to end map. Okay. So set size flash. So it starts with empty. And then we add the curve flash. But we never added the first curve flash to it, right? Oh, no, this should not be an curve flash. It should be curve flash. I think maybe like this. Yes. So now we get nine and three and four and five. And now we just have to clear the ones that are, have been, that are larger. And so updates a case num map in C of okay. And now clear flashed. Okay. So clear flashed of MP is equal to, so we get the keys of the map. Okay. That's all the way here. Data map strict. So we get the keys of the map where mk equals map dot keys MP. Okay. So concat map a map MP map. And then we do dollar a map dot keys. MP a concat map map. Okay. And then we do filter a larger equal to larger than nine of the map dot of map dot keys of MP. And then this one is, is this wrong? Oh yeah. Okay. It's just bang. Okay. And we, this was going to be a concat map. So clear flash returns a list. And we do set dot unions. Where ncs equals this. And we say MP map dot insert. Okay. I'll just map dot insert to work again. Map dot insert. And the type is a, yeah. Okay. So it's going to be zero and set as a MP. And now it does not happy because it's not happy here. Couldn't match type. Okay. Now let's see it again. Okay. Then we have all the new zeros. And then we have the threes and the fours. Okay. Let's get a printer. Right. I'm going to call this, I think this is flip map. Right. In our case. Let's see. I think so. Yeah. So it's a flip map curve MP. Okay. And this is even further out. Let's see. So flip map. Let's see. And we know that it's not going to be in the multiple. Yeah. Okay. Okay. So let's see a print st is going to be a map int set int comma int to IO print. All right. Thanks for the follow. So we do a map and then we're going to say a X from a zero zero two. So we have a map dot from list dollar flip map and P. A flipped. So. So we do a map and then we're going to say a X from a zero zero two. Zero two nine comma Y from zero two. Let me just see what this is. X comma Y a X nine a Y zero two nine. Okay. We got to flip it around. So we do X comma Y. And then we flip them around like this. Okay. So this is going to be the keys in order equals map and keys a print key keys in order print key equals a case map dot. So flipped map a flipped key equals a of just V is going to be a put stir V. Oh, now I don't know. I won't have the lines right. Okay. Let's do it differently. This is not going to be an IO. It's just going to be a string. Okay. A map a print lines zero to nine map a to line and then a to to line equals L equals a map. And then this is going to be flipped and map dot bang over a X comma L where X comes from zero to nine to do to do to do. And this is a to line. Now this is going to be a list of ints, int com, a list of list of ints, right? But not happy with that. Wow. Yeah. Okay. Okay. Let's say, so this is like this. Now, where are we getting this from? Okay. Let's actually say here do in read input. Okay. And we're going to take this make map as well. No. Okay. Let's, let's just do it a bit differently. So we just do task one. But we are going to say there is show print sd dollar mk map Y indexed. And so what we also need here is we say. Yeah. Okay. Because we kind of want the ones and zeros. Right. So let's just have this to be string. So we say map to line a map flipped. Dig it. Int to dig it. And this is what this is not in there. What are you complaining about? To dig equal I equals to dig. Something I to dig into jar to dig to dig a unlines. And then I don't need this actually. And I don't need the around here either. And what is it complaining about now? Why not? Okay. Yeah. Okay. I don't like that actually. So I'm not going to do it. Now, is there a function here? Yeah. I'm just going to go ahead and import data to jar. Now let's see what the typed holes have for us today. Found into jar into digit. That is a valid whole fit. Nice. Int to dig it. The map, the given key is not an element in the map is going on there. Do, do, do, do, do, do, do, do, do, ding, ding. Okay. Let's see. Trace show ID. What's going on here? 00001, 00203, 0045. Okay. Right. Right. Because it's not a XR, YR. So it's going to be up to YR. And this is going to be up to XR. Because we don't, so we have a different range for the, like the example one, right? That's fine. Okay. So this is going to be a make map index. Okay. This is going to be print st f5.5. 4 comma 4. Trace show. Okay. So 1199. Yeah. Okay. It's just showing it directly, right? Okay. So this is the after one after the first one. Okay. Then we want to do the step. Okay. Okay. So R is equal to, so trace print st f4 of RR. And this one is, why is it not happy here? Okay. Let's run this. Why is it saying CEAC? Oh yeah. Because, why is it saying that? Is it because it's not clearing? Probably, right? Okay. So this is going to be, okay, but at least we're getting those correct, right? But we, the clear flashed here is apparently not working. So let's see. Because I insert them into zero, but I don't actually cancel them out. So we say here, map.delete. So we say, okay. I'm just going to say, fold R, map.delete mks equals mks. mks. All right. So we did, we did the first step. We're still on part one. I really hope that whatever we end up with, it will help us part two. Okay. So this was after step one. So let's just say here, there's going to be int comma int. And we say, c comma mp. And we say, so this is like, last is round. Okay. int nmp or mp prime is equal to this one. And we return ftr plus c comma mp prime. And then this one has to be a zero comma like this. Yeah. Okay. And then we can just apply, see if we say step. Step. And we get the four, five, six, five, four. Yeah. Exactly. Okay. So how do we apply n steps? Let's say a to a to int to a to a. Okay. Let's just define it. Apple n a zero f equals a equals a. Apple n a n f a equals a. Apple n. I think this function must exist somewhere, but whatever. n minus one f f a. So let's apply our function a the result. Let's say it's apple a hundred. And then let's say this is, we're going to go to nine. And we're going to run it on the example. Okay. So five, two, two, two, nine, nine, two, two, three, five. So this is it. Oh, we get to step. Oh, no. We're not getting it right. Okay. So before any step five, four, eight, three, two, one. Okay. And then, okay, let's just, we got this. Let's apply it zero times. What do we get then? Zero. And we get the five, four, eight, three, one, four, two, two, three. Hey, thanks for the follow tomorrow. Okay. Now we apply it once. We get six, five, nine, four, two, three, three, four, three, eight, five, nine, blah, blah, blah. Okay. After step. That's okay. So let's apply it three times. Okay. So then this is one. She's here. It's like eight, but it should be doing, but we're saying nine, nine. Okay. Let's call this John, not apple, just sim. And then we just say here. So sim zero a is going to be a X comma a is equal to a trace we have before print sd print sd a a sim and a X comma a is a C at. So this is going to be sim. This is going to be step. So this is going to be a step C. What is wrong with this one? Could match type expected type a to do, to do, to do, to do it is because I should return X comma a here. No. Fixing the int and a int set in comma int and returns an int separate. Okay. Now print sd a. Okay. I forgot to do the nine comma nine comma nine here actually. Okay. And that's what we want to do here as well. You want to trace. I think we have to do it like this. I think we have to do it like a trace a print sd nine comma nine comma nine. Okay. And then this one becomes a sim a. Let's see it two times a zero comma make map Y index. Okay. So we have, we start with this one five or two, two, two, two, one. Then we get the next one and then eight eight zero seven four seven six five five five. Yes. So it's eight five eight eight eight six six eight five eight eight eight six six zero nine eight. Maybe, maybe it's because I should say so this is maybe a sim nineteen nine. So let's see. So sim two. The final value was a the same as saying after step two. Right. So after step three. Okay. Right. Something seems to go wrong there after step two. Right. Because we never get this. What did we say? All right. We're not on there. We don't have a right number of flashes. Right. Ding, ding, ding, ding, ding, ding. Something goes wrong at some point. Yeah. Okay. We might have to say think this whole thing. I mean, so it's a bit weird, right? Because it is a because it is so dim is equal to X is equal to the length. Comma length input and then there should be dim and they should be let's say here. Tiny X. Oh yeah. It's minus one. It should work. Right. These are the dimensions we want to print. Okay. So we get one on right. And then we get three, four, five, four, three, three, four, five, four, three. Okay. And then after step two, we get the four, five, six, five, four, five, one, one, one, one, five, six, one, one, one, six, five, one, one, one, five, four, five, six, five, four. Okay. So this one, this one works. Okay. But it's something with the example that doesn't work. Okay. So let's see. We should have in step three, so we have a zero here and zero here, two zeros, three zeros. And then we have four zeros here and four, five, six, five, nine, four, three, seven, four, five, six, seven, eight, seven, four, zero, six, eight, four, eight. Oh, the last line seems to be going wrong. Okay. It wasn't wrong before though. So when does it become wrong? So it's correct in the beginning five, two, six, and then we get six, three, seven, six, three, nine, four, eight, six, two, six, three, seven, yeah. Six, three, nine, four, eight, six, two, six, three, seven. But then here it drops out of sync. So eight, four, eight, and there's like a nine here, which is as if it wasn't counted. Now why does that happen? What if I remove eight, seven? That's annoying. There's like only the one line that goes wrong. And even if I change it so that it, whatever I do, less than or equal to nine. What is up with that one? Let's see, does it also happen for our tiny X? Four, five, six, five, four. What happened there? What is going on though? Let's see. It's six, three, nine, four, eight, six, two, six, three, seven. Yes. Five, nine, five, seven, nine, five, nine, six, six, five, yes. Seven, nine, nine, three, nine, nine. Two, two, four, five, two, two, four, five, yes. Three, two, eight, seven, nine, five, two, eight, three, two. Yes, five, two, seven, eight, six, three, five, seven, five, six. Five, two, seven, eight, six, three, five, seven, five, six. Seven four six eight four nine Six five eight nine. Yes seven two five Two seven two five two four four seven two five seven Yes Six three seven five six six seven two eight four. Yes So what happens here? Like what is the difference here? What is going on? What if I don't remove their cells work like that? Okay? This is very annoying, right? Where it's like why? Why is that one thing one guy off? Okay? Let's ignore this curve flash Let's write a new definition of gun curve flash where and curve flash Is equal to we get the keys? so we get the keys in the end map that are larger than Nine we take the union of all the ones that are flashing. Okay, so this is are they new flashing and Then we do an FLS Set dot and we remove the ones we've already seen Flash. Oh now it doesn't even work. I might there's something else as wrong as well Okay, so we move so these are the Nfls. Oh, this should be in the end map, right? Sorry about that Okay, it's incorrect except for It's like doing two steps at once Okay. Well, what would we do like? Okay, let's just do it like completely a map based. Okay a set dot empty empty and then add one to the map Flash, okay, and then We remove the curve flash okay, and Now this whole thing changes so Let's just Remove this whole thing for a while Don't know. Okay. Then we got another case of the editor freaking out. Okay? so so we added one to the map, okay, then we Then we do like this and this and flash a We Find the new keys. We took the unions of the sets Be larger than equal to nine. We take the units of the sets. Okay These are the new flashing ones. Okay, then we take the and flash And then we update the numbers Okay, and so and then we just count they We do and How do we check it? So we say case and set dot null and Flash Equals a set dot size flashed And we just return the Curve a Curve mp, right? So this is this is gonna be Let's just call this mp. It's just gonna be the mp And this is just mp and this is just a mp, okay, so we take the look once in the If there are no new flashers, then we do okay, otherwise it's equal to flash set If flashed flashed set set dot union and and flash and map and it doesn't like n flash because n flash is a set okay, so we filter and we take the unions and This is like a set union, so we're not actually counting the okay Now we're back to kind of where we were but that's okay. And Will we get the NFL's? My editor is like starting to crap out of me again, okay, we get all the keys and then we Okay, my concat map this It's always telling me to fuse the concat map, but then whenever I tried to do that It doesn't actually I'm doing you something wrong there Okay, so we these are the new flashers and Then we Sort And we a Filter set dot member Fashed and now I can't figure it out because it's so this NFLS should be And the NFLS right, okay, I think it's that is a flip here and then just let's just check if n flash is empty Otherwise union So I take one from each and then yeah, okay, and then 55 hours. Just we're just stuck in some mess Just absolutely stuck and we've been here for two hours Let me check What's going on I am actually just gonna check one Domino's clothes is Okay, close at 11, so I'm gonna do 45 minutes more then then we're gonna keep up Okay But we started out good, right? We almost got there and then we had less like a one Error somewhere and it didn't update the example and now it's all It's all rubbish Let's just undo all of this work. Good. Am I seeing am I my my undo buffer? It's wrong So I can't even know if this is correct or not is set dot size Lashed I think was like this. Oh my god. All right. This was before I fixed it But this one works for at least this one, okay, so I'm just going to run on the input and I'm just gonna see If it's a You know, maybe this this isn't an error in the example right, so he simulated for 101 steps we get 1400 I'm just gonna see if that works No, okay, so it's not it's not in the Example, okay. Hey. Oh my god. Now this stream is gonna get DMC aid Because it Spotify started playing some radio stuff Okay, we'll see we'll see what happens You'll actually check see this is The vermelo keyboard. It's nice Pretty nice. Let me see So now I'm thinking of it. I know what to do. This is annoying No, I might have to like know I have to edit the video right I have to like change it and cut it and What is going on with this nine here? It's just weird right it works for the tiny example Okay, and it works for the whole Example except for this one nine here and it's just it's just bizarre. I Think it's crazy bizarre Usually errors are like either it not nothing works or it kind of all works maybe Now we have to stare Stare at the code. Is it like a is an off-by-one error? Somehow an off-by-one error for one of them, right? It's like what? Okay, so we look at the ones that are Nine, okay now we're gonna we're gonna rewrite the whole thing We have to do it. All right. You have to do it Okay, we're just gonna do do it the super crazy Boring way, okay So we have a list of list of ints Okay, let's just copy paste this all We're just gonna do it like the Slow way, but where there's no chance for Anything to go wrong Okay Now this is just gonna be Y indexed Task one prime. We're gonna say task one Prime, okay, let's see and we get the list Okay, and Add one it's gonna be a map of it Map of these Int comma int comma int. Okay. Now. Let's actually so we have it and then we do The let's do still we can still make it into a map map From list But now it's a Y indexed. Yeah, so we do a map from list Y indexed, okay, and then a So step it's gonna be I think we can do like map LMS map LM map keys keys map LM Map keys, why can't we map the elements? We can do map. Okay, we can just do map step, okay, so we first we do a And one is equal to map plus one We do add one and it's gonna be map dot map Okay So a step is gonna be Where ink one is equal to map map dot map plus one so Kerr MP a Kerr MP and then we say this is gonna be Ink one and let's say this is step Okay, so first we Increase it by one Okay, and then we're gonna say a We're gonna filter So it's gonna be a to pull So it's filter Okay a new flash flashing is equal to map not filter larger than nine ink one Lashing Okay. Yeah, no none of them flash. So let's do it for that tiny X Tiny X. Okay, so these are the ones that are flashing in the First one. So let's let's just say this is gonna be So map file filter equal to 10, okay, this is equal to 10 And So we're gonna say flash So we're gonna send it's gonna be the initial one is gonna be a flashing Ink one Okay, let's just say flash. Okay, so flash Flashing this is just a list MP is equal to So as there's none of them are now flashing So flashing So have flashed and flashing So have flashed now, let's just say flashed Okay, so we have flashing MP. Okay, so then we go Okay, it's gonna be flashed flashed ink one Okay, it's gonna be flashed Okay, and Yeah, okay. So here I'm going to say so I'm gonna take the list of Okay, it's gonna be flashing flashed and flashing Okay flash flashed Flashing MP is equal to okay Where an MP is equal to map So I'm gonna say take the coordinate the Coordinate and We're gonna find the Okay, so where and Flash is equal to concat map nays flashing Okay, then we have all the all the new ones that are flashing and Then we're gonna say a Alright, so this is gonna be a map. Okay, there's gonna be a Map dot keys Flashing And defined Okay, and flashed is going to be it's gonna start off as a Empty set. Okay, what looks closest? Alright, thanks for the follow Sanctis. I hope this Miss one and soon actually so and for the new flashing And and and map Is going to be a So we have the flashing so we can say map. No, we're gonna fold our C We're gonna say a map. Okay, actually so n flash. So let's see No, we need the We need the Yeah, okay, so we have the n flash So those are the neighbors. We're gonna do Group we're gonna do sort and we're gonna do the length thing map L at X Whatever X comma Length of L. So these are the new the new flashing with their lengths So and flashed FST and flash okay, and then So those are the new flash Accept. Yeah, okay. This is a new flash. Oh my god. These are the names are getting Very they're not not going well Okay, so n map is equal to we're just gonna go over the ones in new flashed no n flash We're gonna say Fold our And we're gonna say C comma V C comma n Update there's something called update update Okay, adjust Adjust with key, you know update Okay, so Yeah, uh, okay update So we're gonna say fold our we're gonna say update And we need the function so we're gonna say just dot Plus and and we're gonna give it the key C and we're updating Mp right like this MP and let's just say M map dot update M And then we say MP and we say and flash This is a new map okay, and Now flashing Is equal to the same thing and map Okay, and it's okay that flash flashed flashing so if it's if it's empty MP then we return set dot size flashed comma We just return yeah set that size flashed and the MP Okay, and this is gonna be set it up empty and this is gonna be set dot from list So the new flashed Yeah Because so because they're not gonna be equal to 10 more often, right? So the if it's otherwise we say Flash a flashed set dot union and flashed and the new flashing is flashing And this is in map. Okay And No, let's see what it says. Oh now it's a loop. Why is it a loop? We did something wrong here Okay, we we don't actually need this flashed flashing blah blah. We just need to say Map dot size a Map dot filter larger than 9 MP so those are the ones that flashed Let's see. This is also a loop. Yeah, so we don't need this and flashed. Oh now I might be like flashing them twice Because they didn't get flashed again unless I remove from the neighbors the This one because then we always Add to them. So flashed is gonna be this and the end flashed are the ones which are here But Now actually we have to do it like this Again map we update we say just plus an MP and flash And then flashing is like this Okay, so we add one and then we have exactly those that are flashing and I think the map size and all are okay This is remove this step one is equal to The lashing right, okay, I think that's where the loop was happening. This is it be This is flashing prime. There should be flashing prime And then if I remove not increasing yourself and then this is flash flashing filter see not equal to dollar a Let's just call this area And then we call this one area. So it's like not It's not actually the same. Yeah, okay now Let's print the trace ST. Yes, so sim and It's a sim 0 a X comma 8 is equal to trace We had the dim somewhere here. We just do it again deem trace print ST deem a Dollar and then we return Return X Sim a n See at X comma 8. This is gonna be a case we're gonna say nf comma a prime step of a Equal to a plus X a Okay, so we so the new flashes. So because of the result of we had this better before right? Okay, let's just change the signature of step again. See Cmp a an F comma MP and MP is equal to flash flashing in one And then this is equal to C plus an F comma an MP so simming C at a is equal to trace print ST dim a Sim n minus 1 C and then we just do zero Zero comma and it still should say nine and this thing Then we say a sim zero sim zero What does that say? ST alright Print ST is the old one. Okay. We don't care. Let's not just let's just not print it We don't care. We're just gonna see what it returns. What does it return for the input not for the? Example day 11 it returns Zero All right, because it doesn't actually step 9791 Let's see here After a hundred steps have been told of six hundred fifty six flashes After step 10 up to a little of okay. Let's see. Okay. That one is all so wrong Amazing Okay, let's just write a new Print ST that kind of does the same thing here print ST It takes in a dim takes in a map Int comma Int to a string Now we don't flip it. We just say We just say MP Okay, and then we do trace print st prime dim Oh, we still let them again print st prime dim a x otherwise Trace print st prime dim a Yeah, oh, I think it's because we don't clear it. We forgot to clear it. I think that's the thing Not a digit 16. Yeah, I think that's the problem So we we get the new map and then we do mp and then flash of the last one Is this one and then we say we're going to say we just say here a clear flash mp so clear flashed mp Is going to be equal to where mks equals to map dot filter larger than 9 mp map dot keys um map dot And then we do map with the key Oh, no, I think we can actually just do a map map dot map a x If x larger than 9 then 0 else x of mp So 1 9 and then 3 5 and then it just turns into something like that. Okay Let's see now if we do it on the example Well, we still get the 9 here I don't I don't get the 9 like now we've done it two ways and we get got get the exact same 9 there for some reason and like it's correct otherwise So after 11 we get 204 What do we get of 101 17 20 Yeah, we're supposed to get 16 56 after Okay, maybe that's something in the description that we're missing Then any octaves within a jullier greater than 9 flashes this increases the end of life of all vegans adjacent octopuses by One including octopuses that aren't okay So I think maybe it's because so here I take the ones that are exactly 11, but they might have been They might have received before yeah So let's say a Again, that's a good point. Okay, let's see. Um flashed up before Is map dot keys? Um map dot filter Larger than 9 mp, okay now a flashing prime is going to be larger than 9 filter set dot not Set dot member A flip. Okay, let's see if this one works. Okay Yay, so what are you missing? In this one at least was that a That they were getting like they got If you got two I think like if you if you like got so many that flash twice or something Okay, but now if we'd run it for 100 We get 16 56. Okay. Now, let's run it for the input. Okay. I think we might Let's just task one, right? What are we going to be doing for task two? Okay, 16 20. Let's go with it perseverance Finally got no wonder. Okay. Let's uh see part two but Okay, it seems like into the facelift right after I get however better option the finish needs to be synchronizing Uh in the example by the first time octopus flashed simultaneously is step 195 After step one. So if you can calculate the exact moments When the octopuses will all flash simultaneously even they'll get to the kevin What is the first step during which all octopuses flash? Okay So when do they all flash task two? a Okay, let's see Uh cc current p. Okay, so Sim until flash So sim until flash of uh an Uh mp is equal to error. So we have this step So here we don't need the we're not going to count them actually We just do the current p But we do want the uh, so the step We go we do mp prime comma f ts Flashed this step equals a step of mp so case a flashed this step equals a times nine Oh 10 times 10 times 10 equals and other Why is a sim until It won't seem until flash mp prime on sim until flash And All right. All right. This is actually flipped mp prime now flash this step Oh my god, what is going on? Okay, so sim until flash and a mp equals Where okay, so this one is going to be uh, so the step we're going to say, uh flashed mp equals step mp right mp prime and then we're going to say if flash equals 100 then Else Sim until Flash. Oh, yeah, I think I forgot to just do n plus one mp prime Then n else a Let's do trace print sd prime mp And this one won't work. Where does it? Okay. Let's just do this Okay, it's step 370. Let's Check that I think it's like maybe it's uh step 371 then trace Print st prime 9 comma 9 in a We didn't test it on the example either, right? mp prime And then It's n plus one. So what does it say? What does it say for the example? A After step 195, I think it should be yeah, okay And it's 371. Oh, it's finally over only three and a half hours But we persevered And what did we learn? Just rewrite And I mean, yeah And then like so we were trying to do it you know Hard way And it wasn't quite working out And then there was like a one nine somewhere That screwed it all up but I yeah, I I'm not even sure what we were doing wrong in the first one But then we just did it again And I think we kept it simpler. I mean because we were I think we were like trying to optimize it Too fast first Okay, thanks for tuning in to this extremely long session Uh I'll have to edit the video because I think I was playing some copyrighted music there for a while But uh, we're good now And I'm gonna try and get my pizza. All right. Thank you all for tuning in and yeah, see you tomorrow at seven And it's not gonna be a double feature because we've caught up All right, thanks again for tuning in and Uh, see you tomorrow Okay, bye-bye