 I was indeed muted. Sorry about that. Now I'm not muted. I hope. As I was saying, thank you little Annie for the happy affiliate. Thank you Moomijumala for letting me know I was muted. That could have been bad. So we put it up at the VS Code today. And so it's a bit better than VIN because the Haskell language server works great. I mean, you can also set up for VIN, but I haven't done that yet. Does the audio work today or now? I hope so. Let's start with day four of the VIN code. Ah, it's fine now. Great. Thank you. And I made like a last minute change. So that was what happened. Anyway, let's go. Day four. Scratch cards. So we were missing snow. We got thrown up by a trebuchet. We found some gears for the gondola. And now we are trying to do something. Okay, so we hook it up. Circle of snow. Oh, there's more. It's warmer than it was on Snow Island. Humid. There's an owl sitting on the cross station. Oh, hello. I'm not sure. That does sound like something. This island island. But the gardener will know. He's, there's a lot of lore this year. Yeah, so yesterday we did three days. Hopefully we can do the same today. I don't think so. Because it's supposed to be tricky, especially in day five. But we'll see how far we get. In the next two or three hours. All right. And as I said before, you might see little Annie's hand pop up on stream. So beyond the lookout. It's an Easter egg. All right. So different island when you come up with a quick better naming scheme. Okay, let you borrow my boat. You go with the gardener got all these scratch cars. Can't figure out what I want. There's got dozen scratch out with the opac covering. So I just scratch up here. Got one. So this number set up. I work a bar, a list of winning numbers and the list of numbers you have. Okay. Okay. As far as the elf has been able to figure out, you have to figure out which of the numbers you have appear in the list of winning numbers. The first match makes a card worth one point and each match after the first double sub point value of that card. Okay. And cool. So let's get parsing. Example. Example is going to be a list of strings. Example equals put this in here. Let's op it all in. Okay. And what is it complaining about now? I think it's not actually complaining. I think it's just slow. Let's go here. Day four. Day four. Day four and time day four. Yeah. There's no parser. Okay. Cool. So let's say data card. So we're going to ask card ID and we're going to have nums. We're actually going to have this to be a set of integers. And we're going to have winning. Let's just make this a list because it's easier to parse it that way. And then winning. Maybe we have to fix it later. Let's see. Deriving. Thank you. Show. It kind of keeps on to the parse errors quite long. There was an error here. What is up here? Let me see. That's how you do data now. Maybe it has some illegal character. No, I'm not getting the parser anymore. I don't know what happened there. Let's see. We just arrived. Show. Now parse card is going to be string to card. And parse card stir. So first we're going to say a card space rest. Split at split at how long is it? One, two, three, four, five. Split at five string. And then we are going to say CID stir rest. It's going to be span is digit import. Thanks Fabian. I think Fabian has tuned in every year. It is a whole vibe. It's been a long journey. Okay. Now we are going to let's just say that this is equal to card array add int set stir. And we are going to say here a language gg 2021. And let's do print map parse card. Oh, no. Card. An example. Okay. We parse the numbers. Yeah. Okazaki, for those who don't know, wrote the book on functional data structures in like 95. And it's just it's been the standard since then. Let me see. We had like split on somewhere here. Maybe it was in day three. I feel like what was it day two? Yeah. Split on. I'm just going to copy paste it. I should have like a U2 library that I import from. I don't know. I feel like then you have to watch every show to know that continuity, which is a bit annoying. Okay. Then we're going to say a so ns stir, ns stir, we stir is going to be split on. And then we're going to split on this bar character here. Okay. And then, okay, we're actually going to ignore the first character here. Or no, actually. Okay. And then we're going to take ns stir. It's going to be split on ns stir. And we stir is going to be split on ns stir. And then we are going to say map read add int. We're actually going to trace it now. Yeah. So parser combinators make parsing this super easy. But they also introduce like backtracking and stuff. So it's actually not that bad to just hand roll a parser. If you know exactly the format, right? Okay. I need to dump the semicolon and then let's filter, not no. So I was actually working on, I'm working on right now something where I just, I don't have that much memory. Like I have a 500 megabyte file and I need to parse it. And I don't have the memory to kind of be backtracking all the thing. So what I do there is I, you know, I just write a, you know, because I know exactly the format and there's no complex cases. So I can actually just hand write the parser. And because I know exactly the format, it's a lot more efficient that way. So yeah. So parser combinators are super good if you're doing something complex enough, but they're not always the best. Let me see. Okay. Let's see. 48, 48, 83, 16, 17. Okay. Okay. As far as yours, you have to figure which of the numbers you have here in the list. Okay. So now we're just going to do and gg. So the one I read is also just like the default read parser combinator. parser combinator read, which is this read P. And then you can just kind of integrate with a read instance. So then you just basically define the read instance using this read P. And you have to flip between read P and that other one, which is read S. And then you can go from read S to like a read instance. And it's super nice, but it introduces backtracking. So and which is fine when if you're but if you're running out of memory, you might need to hand roll something. And even so this one is not the greatest, but then I moved on to a I didn't go to mega parser, but I went to like the other parser, like one of the parser libraries as opposed to be super efficient, and it was still slow. So it's okay to hand write a parser if you know exactly the format like we do here. So let's say import data.set qualified data.set set. So now to do part one solve is we're going to take a card and we're going to turn an end a num winning. So num winning of a card. And we don't care about the ID here. NSVS is equal to be going to be set dot from list NS. And set dot from list BS. And then we're going to do a set dot intersect. I think it's like that. So we're just taking the intersection, yeah, intersection. And then we are going to do set dot size of this. Okay, let's now do map num winning.parseCard 422100 card one has five winning numbers. Okay, which okay, so here have card one has five winning numbers. Yes. And then you have often you have four of them. Yeah. Okay. So we have four. And then it's eight points. So let's write a two to the power of the number of winning. This is the power of none. Okay, we need to do from integral, but it's actually yeah, so we need them. We need to remove one first. So I'll get eight points, two points, two points, one. And here we're getting 0.5. Because because if it's going to be negative one, okay, let's just do it differently. f let f equals, I have number is equal to f and larger than zero, then two to the power of n minus one, else zero. And we're gonna, we're gonna do this. Let's do it. There's also a pred function for removing one. What do you mean? Ah, but the predecessor function. Yeah, okay. So if you negate, yes, that's a good one. Let's see. Eight, two, zero, two, two, zero. And then do some 13. Let's do part one. And then we need to put f here. And let's say print part one, for example, 13. I actually want an int here. Two integral. Maybe I need to do a round. Nice. Let's see. 13 points. We get the possible input. Let's see, a new file. Okay. Now read file input into a print dot part one dot lines, preload dot read no parts. That's not good. Let's see here. Trace, show, ID. And let's just print out the string card. Oh, okay, because it has more spaces in it. Let's just say rest is drop while not pasted it. Okay. Right. Now I don't need to show anymore. Two, two, six, four, seven. Let's see. All right. Part one done. Boom. 26 minutes. Not bad. Okay. Your part of writing. So when you realize it was already printed in the back of your card sometime, you win copies of the scratch card below the winning card equal to the number of matches. So if card 10 were to have five matching numbers, you would win one copy of each card, 11, 12, 13, 14, 15 copies of scratch cards that scored like normal scratch cards and have the same card number as the card they copied. Okay. So if you win a copy of card 10 and it has five extra ones. Okay. So this is going to be some functional memorization, I think. Let's see. So you win a copy. Okay. Cards two, three, four. Original card two has two matching numbers. So you win one copy each of cards three and four. Your copy of card two also wins one copy of cards three and four. Your four instances of card three. Wow. You win four copies. Okay. So process all the original copies, scratch cards until no more scratch cards or one, including the original set of scratch cards. How many total scratch cards do you end up with? Okay. So first of all, we don't need to care about the actual numbers. Okay. So we are going to we're going to do part two string. So first we're going to just return a list of the cards. Okay. Part two, example equals. Okay. So we're going to map. Okay. We first we have to parse the card. And then we are going to say card to see it. And we're going to say card, ad and winning card. So let's print. So just for each of the cards, we're going to see how many of them are winning. So one wins four, two wins, two, three wins. Okay. So we're just working with these numbers. We don't care about the actual numbers on the card, which is good. Your 14 instances of card five, one original and 13 copies have no matching numbers and window markets. One instance of card six. So now we have to figure out a good data structure or algorithm here. Let's see. Let's see. Okay. I think maybe we can just get away with something quite simple. So we'll have like a list where P two, so we're going to take the list of ends of ends of ends. So what I want to do is I want to say P two. So if I have here, so I'm just going to take the first card and I'm going to say I have one instance of it. And then I'm just going to add kind of instance numbers to each of them. I'm going to see if it works. Okay. So this is going to be like this. Okay. So now I'm going to construct a new list and start. Start is equal to, so it's going to be one X and map zero to X's. So then I have one copy of the first card and then zero of all the others. Okay. Now go. Empty is just going to be empty. Go off. This is copies. And I don't care about the ID, but I care about the wins here. It's going to be X's. This is going to be, this is going to be C. So this is going to be the number of the cards. And this is the ID and X's. Okay. This, so for this one, I'm going to say a where. And so the edit and the rest is going to be split at win X's. Okay. And so then for added, I'm going to say edit prime is equal to map and C is going to be, so it's going to be an, okay. So we're going to add number times ANC on edit. And then what we're going to do is we're just going to return C. See, concatenate it with go edit prime rest. Okay. Right. I need to combine these lists. Let's just say go start. Okay. No, this is not, it's actually not like this because this is going to take, if it's zero, it's just going to say one. I think it's maybe just N plus AN. Let's see what happens now. So I added with one copy of card one, two inches of card two. Ah, no, one inches of card two because all of them have one. I start with one of all of them. So I get one inches of card one, two of inches of card two, two, four of card three, eight of card four, 14 of card five, and one of card six. Excellent. Now, how many total scratch cards do you end up with? Ding, ding, ding, ding. Let's see some map first. So starting on the example, let's run it and see if we got the right number. All right. We did day four in 40 minutes. Nice. Let's go for day five. It's going to be tricky. Hmm. But we're doing quite well. Let me actually, I forgot to do this yesterday, get init, get add, we had old Haskell files and then let's do code. Don't get ignore. Oh, okay. Days one, two, three, and four. Okay. I don't have a repo actually. All funny games, little day five part two. Okay. Anyway, we have an hour and a half or more. So let's start with day five. Let's see. We create a new directory, day five. We open up day five that it just says module main where main equals print part one, example part one. Example is going to be strings usually. Example equals an update list. Okay. Okay. Do cd day five. Okay. Let's see. You take the boat by the gardener, garden, water source, island, island is the water source. Okay. We ran out of the sand to filter it. Can't make snow with dirty water. Don't worry. It's over. It gets more soon. I've been missing making. Okay. So much pressure. Okay. While you barely have time to agree to this request when it brings up another, while you wait for the ferry, maybe you can help us with our food production problem. The latest island, island, almanac, blah, blah, blah. The almanac has, oh my God. That's a lot of stuff. Let me just see the input. Okay. This time I'm actually going to just put the example. So in a file, because it's quite long. Yeah. Now we're getting into there. Let's see. Okay. And so what is an almanac? Okay. See the soil map. So it's 514. Okay. It's all the seeds that need to be planted. It also lists what type of soil to use for each kind of seed. What type of fertilizer to use for each kind of soil. What type of water to use for each kind of fertilizer and so on. Every type of seed, soil, fertilizer, and so on. It's divided by the number, but numbers are reused by each category. So I want to do this. He doesn't want to do this. Okay. Seed to soil map, fertilizer to water map, water to light map, light to temperature map, temperature to humidity map, humidity to location map. Because I always describe how to convert from numbers from source category to numbers to destination category. That is section seeds. That is our seed number, the source to a soil number and its corresponding destination. One more. It's got entire ranges of numbers. It can't be converted. It's like extremely contrived, right? Each line within a map contains three numbers. The destination range start, the source range start, and the range length. Okay. So it's always three numbers. Okay. Okay. So let's just start parsing this. Almanac, data almanac is equal to almanac seeds, seed to soil. Let's just start with these triplets. Then soil fertilizer, soil to fertilizer. Okay. Fertilizer to water, water to light, temperature to humidity, and then humidity to... Okay. First we're gonna do where LS equals and lines example. So what I'm gonna do now is I'm going to... We're just gonna split this list on the spaces. So we're gonna copy the split on function again, but now we will change it to be an equality. Actually, a... Okay. C string, R, R, S, and not equal to C. I think this is actually correct already. So, and now I'm just gonna do here a split on, let's just see what it does. G, C, D, F, I, L, H, S, O, D, 5, 10, D, 5. Okay. And we seem to have managed. So now a seeds equals... So this is actually gonna be like this. It's gonna be a seed stir and then SDS stir, SDF stir. Okay. It's gonna be a seed string. That's gonna be special. And then it's just the rest in order. Have you already done the first tone day? Yes. Keep on posting these to YouTube like last year. I do, but because I'm a Twitch affiliate, I actually... It has to wait 24 hours before it can be posted anywhere else. So I've uploaded the video and it will be available at 11 o'clock. So in two hours for the first three days. But now we're trying to catch up with... So we did day four and day five is supposed to be hard. So I hope it works out. Okay. Seed string. Okay. It's gonna be seed string. Let's just make it like this. So SDS. Okay. And then SDS. No, because I want to do the same transformation of all these. Okay. Seeds is gonna be seed stir. So we're just gonna say seeds space. Okay. And rest is gonna be split at length seeds. Seed string. And then there's a bunch of numbers. So we're gonna say endsters is split on rest. And then this is gonna be equal to map read add int. Endsters language. I don't know if I can have guards here actually. Okay. So the seed string here is a list of strings. Right. But we know it's just gonna be one line. No. That was the problem. In the input. Yeah. It's also one line. Good. So we have the seeds. Now for the rest it's actually gonna be rest prime is equal to map tail on rest. Okay. Just warning me that it's partial. That's okay. That's the rest prime. Okay. Then we're gonna map. So num list where pass. Oh no. Okay. So let's see. Maybe we're actually gonna give the pairs here. Right. Okay. Okay. PR. Let's just say PR stir is equal to case. Endsters split on R1. And then it's gonna be ABC is gonna be map read add int. Endsters is equal to A, B, C. And this is gonna be string here. And then we're gonna we're gonna map the tail and map PR tail. And now this is gonna be a list of these. Right. Nice. Okay. Okay. The parsing is happening. So now I'm just gonna call this maps. Okay. I'm not gonna because we're probably gonna transform it anyway. So max seeds. Maps. Okay. Because it's like you know. This is one to two, two to three, three to four, four to five, five to six, six to seven. Now let's see what happens now. Rather than list every source number and it's corresponding. Maps are the same. So each line within the map contains the destination range start, the source range start, and the range length. Okay. So 98 corresponds to 50 and 99 corresponds to 51. Okay. Second line means that 50, 48. And because the destination is the first one, the source is the second, right? Okay. Any source numbers that aren't mapped correspond to the same destination. So seed number 10 corresponds to soil number 10. Okay. Yeah. So seed 79, soil 81, light 74, temperature 88, humidity 78, location 82. Okay. But do the maps never overlap I guess, right? Yeah. I'm actually gonna flip it. I know it's different in the example, but it's just quite annoying. So 48 goes to 52. So we wanna check the, so I'm gonna, what I'm gonna do is, so it's a range, right? So, okay. How do we go? Here's 79. It's not in the second one, but it's in the, okay, let's just define first the function. That's very simple. In range, int, in range. Well, this is the source destination length. I don't actually care about the destination. I just wanna know if I less than equal to s and no, that s is less than equal to i and i is less than equal to s plus l. Boom. So this gives me whether it is in range. Now, let's see. So transform is gonna give me transform. It's gonna give me int. There's a list of ranges and it'll give me a new int. Transform int i to, okay, it's empty. It's just the same. Transform i source test, range, m at if case, in range, im equals. Otherwise, equals to transform i axis. Now, if it's in the range, that means that we want to do a destination minus source. So we just do it like this. So we're gonna say, see, because this one is like, so 98, 99 correspond to 50 and 51, right? 50 and 51, right? So if you wanna, so then you two do 98 minus 50. Now, this is gonna be as 50 minus 98, which is gonna be minus something that transforms it, right? Shouldn't it be i? Yes, that's a good point. It should be within the range, right? Let me see. So 50, so this one is gonna be 50 and 51. Yeah, exactly. So it's less than, okay. Now we're gonna say transform all, takes an int and a list of list of int, int, int, to an int. Transform all is equal to, is equal to folder. And I never remember what is the type of folder. Yeah, so it's a folder. It's gonna, we're gonna transform, transform. So it's gonna take the range and the number, okay? And we are going to transform with the, let me just flip these here, just so we make it fit into folder more easily. Okay, so we're gonna transform, we don't need to do this, then transform and the initial element is the i and then the list. Okay, so let me now do a part one. We see we have that somewhere here, right? Let's put that further down here. This is gonna be list of ints. We're not gonna use these almanacs. This is gonna be list of ints. And we're just gonna say map, flip, transform all, maps, see it's ding, ding, ding, ding. A transform, all right, 1843, 87, 42. Okay, that's not good. Ah, because it's soil number, seed 79, hmm, dollar take one. So it goes to seed soil 81, 14, 57 methods, transform works, but my folder is messed up, 81, fertilizer 81. So 14, 14 is now going to, ah, sorry, it's because it's fold R and not fold L. So it's going in the opposite direction, which is kind of annoying. But so we're not gonna build up so many thunks here. So it doesn't, it doesn't actually matter. Nice. This is part racing. All right, now it actually works. So we get 82, 43, 86, 35. Okay. So part one is minimum of this. Ding, ding, ding, ding, ding. Okay, no, read file part one. Okay, that's a pretty big minimum. Boom, part one. Fold R is more efficient than fold L. Yes. Because it's because of laziness. Because fold L needs to build up a bunch of thunks versus fold R. Well, fold L versus fold R, fold R. So it is subtle. But basically fold R will build up a bunch of thunks like this. See? So here's a fold R. So here you have fold R. So this is a list and then you're applying the function, right? So here you can apply the function to one right away, right? Because you already have the first argument. And also the 0th element, right? It's the end, right? So you can kind of apply it right away versus with fold F. You have to kind of wait. It's a bit, it's a bit difficult to explain. See? So fold R is like this, right? So F, high one, right? So you can finish doing this and then you start doing this, right? Whereas here you kind of have to do everything first and then you can, then you get the last element and then you can finally start reducing, right? So FXY can be computed using only value of X. Yeah. So, but you can't get away with fold L prime, which is strict. So and then it forces the application right away. Otherwise it kind of builds up a bunch of thunks because it doesn't need to evaluate them right away. So I should, I should explain this better, but it is a, it's a subtle point. So if you have a lot of stuff, it might not be better, but here we don't have so much stuff because we only have like five lists. So it's fine. Okay. Let's continue to part two. This one is apparently hard, but we have 45 minutes for our initial budget. Okay. Three minutes reading. Line looks like a seeds line. Actually it describes a range of seed number. Little Annie Jess Brotson. Hot sip. Not bad. It's quite hot, but good for the throat. 79, 14 values. Oh my God. Second range. Yeah. This is going to be messed up. And it will be very nice if we could transform an entire range at once. Let me, let me just check in out and just see what happens if we do it the crazy bad way. Um, so seed two ranges to seed two ranges. X, Y, rest axis. Okay. So, um, it's going to be equal to X. Right. X comma dot dot comma X plus Y. Right. It's a dot dot dot. How do I always forget this in text? Okay. So there's one. Ah, there's no comma. I think it's not going to compile. Uh, so this is a list of ints. So it is only a few plugins seeds, but we can stream it, which is amazing. Uh, wait, let me just see. One, two, five. I always forget this. It's because I have this extra parenthesis here. It will think it's a list of lists. Okay. Now let's, uh, let's see how bad it is on the example. It should be quite easy on the example, but, uh, because it's not, it's just 28 numbers, but, uh, let's break out the big guns compile with optimizations. Okay. Now it's going to be crazy slow, but I just want to see. Because it's, uh, it's not going to, I'm also, um, um, if it's a few billion, actually, int is not good. Int can take a, uh, it's going to be slow, but, uh, okay. Now we need to figure out how to, how to basically transform a range. I'm going to take a short break, but I'll be right back. Yeah, but this will be running in the meantime. I'll be back in one minute. I'm back. I went to the bathroom, but I had an idea. Um, instead of representing seeds as one int, we should represent it as a range. And, uh, what is a range? Well, a range is actually a list of ranges, right? Because each transformation is going to affect a part of the range, right? So, uh, let's see how we do this. Um, let's just say here, um, transform range integer, integer. And then we have these guys, but not with the, uh, okay. So, uh, transform range. Okay. And then transform all ranges. It's going to be folder or transform range. There's his folder prime still there. Transform all ranges. And let's just make sure that these are all evaluated. So now we just need to implement this transform range function. And then we're good. So the base case is easy. I equals empty. It's going to be empty transform range. So, uh, first of all, we have to, we're gonna have to loop or both. So let's have a, let's look good this way. Transform range, uh, i, x, m, m's is equal to, um, range prime of i and m. So we're going to operate on all the i's here. Let's see. So the affected and unaffected, we're going to be transform range i, n. And then we are going to say transform range unaffected m's. What is this? We are going to prefix it with these ones. Okay. Transform range prime of a, so if there's none left. Okay. So let's see. Let me see here. Transform range prime m is going to be affected so far. I've been affected so far. a, f, u, a, f, i, and then let me do it this way, not actually this way. I think it compiles better. Um, I don't care about the m here. So the empty case is easy. Now we have to write that difficult one, which is going to be transform range prime. So now we're just looking at one. So it's just source destination and links. a, f, u, a, f. And here we are looking at, we are looking at the, um, this current range. So range start, range end, no range start, range length. Okay. Case. RS less than or equal to S. So the source. And so if we're in the range, S less than RL. Okay. Um, so here we're in the range. So now we have to split this up. And we have to split it up by saying, um, so the range here is, um, are you going to split it up? So now we know that this particular range is affected, but how many are affected? Uh, so that it affects, um, so let's just do an if statement. So if, uh, no, sorry, this is going to be RS plus RL. So if a RL is less than or equal to R, so then it just affects the whole range. Okay. Then we just, um, we say transform range, uh, prime RNG. And then all of them are affected in, in a prime, uh, UAF axis. So we're gonna have another case here otherwise. So if it's not in the range, I might be that the RS less than or equal to S might be that part of the range is affected, right? I'm getting a bit confused with other ranges. But the thing is that because you might be splitting up a range, but I mean you get the idea what we're trying to do here. We just have to get this tricky function right. Let me just, uh, see the example. Okay. Let me see, um, transform range prime. So this is the function we're trying to write. And we have, uh, this map source destination, right? And we have, uh, this range, uh, range start, range out. Okay. Transform range, prime. Uh, let's say it starts at one and it's gonna shift everything by one. It can shift five numbers by one. And we are talking about range starts at one and ends at 10. So what this is going to do is it's going to return two new ranges. It's going to return two new ranges, right? It's so, uh, so because it's the numbers one, two, three, four, five, eight, nine, 10. No, that's making it even more difficult. Zero, two, zero and the range length is 10. So it's going to return the ranges, right? It's going to say that, uh, zero. This is a range now. And it's going to return the range, uh, zero, come on one. So zero has been affected. And then these are going to be shifted by one. So it's going to be two, three, four, five, six. And then the other ones are going to be unaffected. So that's going to be six. So this is actually going to be, um, two, two and five, right? The range length is not affected. Uh, well, it is affected. So it's going to affect two, five of these. And then starting at six, there's going to be one, two, three, four. So what's going to happen is that we're also going to have to merge ranges. Okay. So let's see. Let's just make this easy, right? So where the change is equal to D minus S. This is the change we're going to apply to the range. Um, here we're not going to change their length. So as you can say, RS plus D minus S. This is the change operator. I was going to put life to it. Yeah. So the real problem is how to split the range into the correct, like the affected parts and unaffected parts. Uh, okay. So, and then this is going to be UF, MAPC affected. I think this is actually just a trick. Okay. So we have, um, S, two, S plus R. And now what part of this is, uh, what, what part of this intersects with a RS to RS plus R. Okay. Um, this is a tough one. So we'll finish this one and then we'll go to burn. Okay. So let's see. Um, if S plus R, if S is less than or equal to RS, and, uh, S plus R is larger than equal to RS, then we're in the range, right? And then there is some intersection or it's actually this or, um, RS plus RL. Oh, there's a lot of like equalities that are going on here. Let's just see. Okay. So let's just say here, so we're going to take, um, so if the range is less than or equal to S, and, uh, there's, so if there's zero, so now we're going to say zero to one, right? Um, and, um, an RS plus RL, and so larger than S, then we have something unaffected in the beginning. UAF is equal to, um, it's actually just going to be RS to the range start to the length of it is a RS minus S. Ah, okay. I can probably just do it like this. Uh, that you are, you're so unaffected lower, it's just RS and then RS minus S. UAF higher, so the higher part of the range is going to start at, um, S plus R, and the length is going to be, um, something, and then we just kind of filter out, then in F, S and UAF L larger than zero, filter larger than zero, second. Otherwise it's just an empty list, filter something here also, and then, uh, UAF is just UAF L, UAF high. This is such a, because it's not like an interesting data structure problem, right? I think we just, if we just have, get this correct and it's fine. So let's just write the affected range. The affected range, uh, this is also just a case if it's like connected, if it's all within, right? Yeah, this is like, um, it's like an intersection problem, right? And so let's just write out the ranges, okay? R1 is equal to S, S plus R. R2 is equal to RS, RS plus RL. Now I want to see how, how, how they intersect, specifically how RS intersects, R2 intersects with R1. So if R2 is entirely within, so case one, then we just have S, RS plus R, RS, case two, is that they are like this. Case three is, um, is, um, the other case, right? So it's S, RS, S plus RL and case four is just, you know, no intersection at all. Okay, so now let's just compute the cases. Okay, AF, UAF is equal to case, um, case, uh, R1. Okay, so let's check here. So if S is less than or equal to RS and, um, RS plus RL is less than S plus R, case one, case two is S is less than equal to RS plus RL. And, uh, no, okay, case, this is RS less than or equal to S. I think we need more here. And RS plus RL, so RS, so S is less than RS. Okay, so this is RS less than or equal to S and S less than or equal to RS less than RS plus RL and RS plus RL are less than S plus R. Uh, ah, yes, good point. RS is S plus R plus RL. Okay, let's renumerate these because otherwise it's going to get confusing. Two, three, four, five. Let's actually start with this because it's the easiest case in some sense. Um, yeah, let's just do it over. Okay, here we have that RS plus RL is less than, is less than S and, uh, this is actually two cases, right? Or S plus R is less than RS. So then the effected is empty and the unaffected is just RS. Okay, so we've done, uh, let's move right here. I remember doing something similar when I was writing a video game engine thing where you do collision checks, but then you don't have to, um, you don't have to do too much. Actually, um, because then you just need to check the collision here and actually find the range that comes out. Okay. Okay, so here we have S is less than RS and RS plus RL is less than S plus R. So here the entire range is affected and none of it is unaffected. Now we're going to get nowhere into the non trivial cases. So here RS, I'm probably missing more like checks, but it's okay. RS is less than equal to S and S plus R is less than RS plus RL. Okay, here what's affected. So what's affected is, uh, it's just sourced to, so S to R is affected, but unaffected is going to be RS, S minus RS, um, and uh, S plus R to RS plus RL minus RS plus R. I think it's like this. Here RS is less than equal to S and RS plus RL is less than S plus R and S is less than equal to RS plus RL. Yeah, I think that's how you do the same thing here. So here the affected range is, um, start set S and RS plus RL minus S. Okay, and then the unaffected ranges are two, the unaffected one is RS, S minus RS, um, and RS plus RL, RS plus RL, and then um, S plus R minus. So there's some, uh, similar to this case, right? Which is good. Okay, I hope this is, uh, we're not messing it up completely here. Case five. Okay, here S is less than equal to RS and RS is less than equal to S plus R and um, S plus R is less than equal to RS plus RL. Okay, so here the affected range is from RS to, um, S plus R minus RS, and the unaffected range is a, ah, sorry, right? Okay, so here S is within the range, so here S is outside the range. So the unaffected range is actually from S plus R to RS plus RL minus RS. Okay, otherwise error transform range prime uncut case show R1 or R2. That RS plus RS, where does it say RS plus RS? Did I fix it? Okay, we ran it for 15 minutes, it didn't work. And now we're just going to say AFUAF, uh-huh, line 82. All right, so the affected range was correct, um, but actually, so here we're dealing with, we're supposed to be doing, uh, this case. So S to RS correct. And then this is RS to S minus RS, that's correct. This is, uh, S plus R, which is correct. But, uh, you're right, so RS plus RL, uh-huh, wait, so RS plus RL here is, um, this is going to be 10. Let's see, we are indeed in case three. So the second one is wrong. The sixth is correct, but so RS plus RL is supposed to be 10. Okay, and it is 10, but S plus R, I have to have, uh, parentheses. Okay, this is good. And then we're going to just do C on AF. Okay, so now to see if this actually works. Okay, now we have the transform range for one of them. Now let's go back to here. Okay, transform range, form range, mms is equal to, um, so here you're going to say where go. Now we have to kind of look through it. Yes, I know that it's going to be an off by one error somewhere, but we can only hope. Okay, um, okay, so first we do, um, transform range prime. Okay, so empty. Okay, so now we go again and it's going to be, uh, it's going to be affected, unaffected, transform AF, UAF. Okay, and we start off with this and this and I. Okay, and, uh, this is just AF, UAF. Now let's do it here again. Uh, this is affected, unaffected. That's one map. This is going to be equal to, uh, AF and, uh, transform range, uh, UAF, mms, range prime, AF UAF, uh, rrs is equal to, uh, where? AFn, UAFn is equal to transform one range, uh, and here's the m and here's the r, transform one range, a, these can actually be, uh, let's just make them into int, int maker. Okay, so what is the loop here? So we transform one range and we take one of them and then we just, yeah, we just loop kind of, okay, yeah, exactly. We're not adding anything. It's going to be, uh, transform range prime, AF, AFn, UAF, UAFn, rrs. Now let's look at the example. Let's put that, uh, here and now we're just going to look at what happens for the example. Okay, for the first part of the example print, transform one range, no, transform range, transform range, okay, and we're just going to put the 59, 14, 55, 55, 13, okay, and then the maps are, um, no, right, 98, 52, and 50, 52, 48, 57, 13, 57, 13, all right, good. So after the first round, 81, 14, let's see, part two, transform all, transform all ranges and then see, see two ranges. We got to change this one to just be the ranges. Okay, now it's saying transform all ranges. Now I want to just get the, okay, I think what I'm trying to do is, um, transform all ranges, change ranges, sheets, maps on the example, but here it turns an empty list. It's not good. Okay, one minute again, another bathroom break. It's all the tea I'm drinking, it'll be right back. Okay, it's not doing very well. Let's just see first, okay, so then, then transform range, this is actually supposed to be I, okay, so 50 and then 48 of them are bombed by two, and then from, so I don't think this is correct, right? So from 79, so that's 89, okay, that one is not affected by the first one because it doesn't start at 98, and then for 52, so 298, basically, it's going to get shifted by two. Okay, so that's okay. So this is the correct for the first one, and then for the second one, 15 to 37, from 15, so 15 plus 37 is 40, 15 plus 37, 45 plus 7, that's 52. Okay, so that shouldn't affect anything. Um, 52, 53, 54, that's not affected either. Okay, so the second one, the third one doesn't affect any of 15 to 0 to 15, and that matches what we saw before, right? Okay, now let's take three, so from 58, three, we're gonna take eight. Okay, let's just do all of them now. Ah, okay, now it actually worked. I don't know, yeah, maybe I just didn't compile when I ran before. It's definitely not by one somewhere because we're getting a lot of zero ranges. Let's just see, now let's just filter larger than 0.2, and then we're just gonna take the minimum. Okay, so it works for the, this one, the example. Now let's check if we are really killed by those up by one errors, or what? We should really be filtering out those zero ranges right away. Um, okay, there's an uncut case after the first map in the input. That's not good. Um, let's make this nicer. Okay, so here, this is s and s plus r, and then this is rs plus, ah, okay, so here they're equal. I think this should be a little less than, maybe that's the problem here. Um, yes, we'll meet you Muala. You've helped a lot so far, but uh, that's not really helping. Uh, so here we have the case that the end points are equal. Okay, so this one, so it's actually, um, it's this case right here, except the end points are equal. I'm just gonna make all of these equal, and screw it. The minimum was zero. That does not seem correct. Some of them are zero. I'm gonna see if this one works, but I don't think it will. Oh my god, it was the right answer. Okay, we completed day five. Boom. It only took us, uh, an hour, an hour and a half, or two hours. I think two hours, yeah, because we finished day three in like 45 minutes, the day four and four five minutes. Okay, cool. Let me just see, uh, why some of these were zero. So this is RSRL, RSRL, S, or RS, S plus R, S, and none of these seeds are zero. RS, RS plus RL. I don't know why some of them would be zero, because, um, so change changes them, right? So RS plus D minus S, are some of these ranges zero? Like are some of these numbers the same? Uh, so here we have zero source. So I guess it just, for some of them, it just, you know, I worked too long on this, um, already. Like there's just, there's just some case where, um, where it, like the change will be, it's gonna, it's gonna change, um, into a zero and that's, it's doing that. So the length is the same, but, um, so then D minus S becomes RS for some reason, but it's still, that's okay, right? Because some of these, like zero is a valid seed, like index, right? So I don't, I don't know exactly. So I think one of these should not be, maybe one of these should be like a less, not a less than or equal to, so the sum off by one error somewhere, but we got away with it, um, which is good. Anyway, that's all for today. Day one, two and three will be up in 10 minutes on the YouTube channel. And now I'm gonna upload this to the YouTube channel and then it will be available. 11 o'clock tomorrow, European time. I'll probably stream tomorrow as well. We got to keep going if we want to catch up. A, heard a mixed message is about six and seven, but you know, we're at least on day six now. And, uh, so if we do six and seven tomorrow, then we're only one behind, right? So then we can do eight and nine, but you know, it's not really, okay, so six and seven are both really chill, seven, okay. So tomorrow we might be able to do six, seven and start on eight, and then we're probably, we're about to catch up. So we'll see, we'll see what happens. I might have to stream later also because I'm going for a Christmas market thing, I think. Anyway, thanks for tuning in. I hope you enjoyed some Advertisement Code. And what was the key takeaway here? Day four, it was just parsing and then some number stuff. Day five, I think the key takeaway here is if you're getting overwhelmed, just split it into cases and then write all the cases down. Because it wasn't any like, oh, you can just do minus, minus and then it works. Because it was really, you really had to do a case by case. And it worked out. We had a weird part at the end. And if anyone knows why, please comment. I would like to know. All right, thank you so much. See you again tomorrow. Bye-bye. And then, yes, okay. See you again tomorrow. Bye-bye.