 All right Welcome to today's stream Today we're doing day 10. Oh the admin of code and We did day nine yesterday. It was quite fast We've been doing like three hours three hours three hours, but then yesterday it was 35 minutes But of course it was not a triple feature. So it makes sense Anyway, let's get right to it and Hope you enjoy Module main We've been doing This is the fourth day now fifth day we're doing and all the other days are on YouTube already with the last day coming up In about an hour It's gonna be good. Let me see D. Did you do do do anyway? Let's get started on day 10. So yesterday we were Figuring out some numbers for the oasis And what are we doing now? We're using a hand glider To ride over there from desert island All that fun in Ireland Okay Sorry, still recovering from a cold anyway, hot spring pointing in a seemingly inconsistent direction Oh, it's green it's asking where this may be right Landscape here is alien Everything's metamethyl no grass That's pretty metal Okay, it's got the entire field. There's anyone is sensed about with pipes It's hard to tell at first but You make a quick stretch to all the surface pipes J's and a degree, but okay Seven F The price is a stunning precision of the animal Okay, but it's good. Doesn't know what happens. What's true for the pipe has Who's in the acoustics? Okay Didi didi didi didi didi didi didi didi didi So some pipes, I guess we're gonna do some Breath first search or depth first search to kind of we're gonna make a graph and then find a loop There are algorithms for this Okay, this one goes Okay You should find the tile in the loop that is farthest from the starting position Because the animal is in the pipe it doesn't make much of the repetitions You know how to take the longest number of steps along the loop to reach from the starting point Yes, okay So what we're gonna do is that we're gonna have a Like a breath first search And basically we have to just search until we hit the You know we go into both directions And we search until we hit The um We search until we hit the You know we search until we find the same node How long am I aiming to stream this session? I don't know. I think an hour and a half. Maybe Uh depends on how hard the puzzle is, right? I finished the puzzle I'm not gonna keep streaming. Okay, let's uh Let's start with a simple loop And let's just write new file example one Okay, now we are going to We're gonna read this file And let's say do print Read file Check it for a spin Easy d10.hs D10 Let's time it Are you worried about me taking too long or too short? Okay, let's see, um Let's parse each pipe Data dears equals north south East West Let's just derive Eq Show or all that jazz Data pipe Is a connection Between two directions, huh? Just run out for a bite I'll probably still be here but uh I don't know because it seems like a bit of a problematic because this is the first part, right? Then it's going to take a while To just parse it and stuff. So don't worry yet out there um data pipe is a Just a pair of directions, right? Let's see where Let's say deriving Eq show or Okay So parse pipe takes a char and returns a pipe Parse pipe This one is equal to uh connecting North This is right Okay, now Parse pipe like this East to West and these are of course not directed Connects North and east I don't Yeah, okay J connects north and west seven Seven connects south and west South and west And finally f Connects south and east, okay So now Sit it definitely We're getting our thinking sinking sit seating on Um Um Also, I can't hear the music but you should be able to but uh Something wrong with my audio setup Um, but it was discovered too late To do something about it, but at least I think it's on the stream the music and I do think that it's getting the recording for sure Let me know if you don't like the audio quality The problem with this setup I have is that uh I can't hear the process signal, right? I just hear like a straight So you don't have delay so it doesn't tell me the processing but Anyway, it's close enough Okay, so So uh on this map there are three options Let's see it's a a data map entry Is equal to either ground or um start Or a pipe pipe Deriving eq Show board as well Now let's say parse map Take the chart into a map entry And parse map It's gonna be if it's a dot it's gonna be parse map if it's a s it's gonna be start Parse map anything else it's gonna be pipe Parse pipe See, okay, now let's map parse map Uh, we're gonna map map Okay, so what we're gonna do is we're actually gonna do this in the map m m Ground ground ground grounds hard pipe east west Shouldn't it okay, it's start right and then east west And then connecting south and west And then uh Ground okay because i'm i'm using the Nice shirt thanks little any I got it from my Auntie love Okay, let's see uh, so what we want to do Is we want to do a tree right? Tree uh No, it's not actually gonna be a tree It's gonna be a graph Our jcd list representation of a graph mapping each vertex to a list of its successors success successors successors And What is a nice way to create a graph Vertex is just a Int Okay, um Build a graph from a list of nodes new glimpa keys The list of keys of nodes this node should have edges too Okay So what I want to do Is I don't want to do it like this. I want to map map parse map Okay, let's go, uh p.m. It's gonna be To map my parse map Okay, so we do map print pm dot lines Okay, and this is the type indeed Except this is gonna be a string of course Okay, um So what I'm gonna do is I am going to sip this with The indices Let's see. Okay, and then I am going to sip this As well So Now we have We've assigned An index to all of them. Um Okay, so zero One two three four Okay, and then Mm-hmm Like actually to sip with and we're gonna take in the zero and the uh the list And we oh, we're gonna take the index and the list and we are going to map i comma Over the list So now this will actually be like this. This will become an int comma uh like this but we need the Language extension here Gz 21 and 1 Let's go Okay Let's concat this. Okay, let's wait with concat next week. Um Do do do do do Let's say uh map j comma e We're gonna map this into i comma j The so we're just gonna have this be a list of lists of Like this and then Int comma int So it's just clear What all the entries are now we're gonna we're gonna concat Why can we oh we have to concat like this, right? Okay and Then this is gonna become a map of Int comma int to Map entry or to data dot map map import qualified Then a map dot strict as m And m dot from list Dot Okay, um And now we're not gonna map and print We're just gonna print How is everyone doing today has everyone done this before? How difficult it is gonna be Okay, now let's Find the start Uh, let me see We have to filter But can I do find? No, I can't right So let's this is gonna be super bad Let me see m strs Where mp is equal to All of this Strers and then strers mp Okay, so now I want to find a Start loke is equal to filter Let's see a start loke It's gonna be it's gonna be the empty list. It's gonna be only one m dot filter Is equal to start mp And then m dot to list And now we're gonna return the index of the The Chords and Start And the comma chords Okay, and 1.1 is the actual location of the start Good good We are on our way Okay, so now we have to construct the Graph itself, so And the graph so I kind of want to just create a tree. Let me see Like but I don't know The s Every pipe in the main loke connects to its two neighbors Okay Okay, so we just have to look At all the ones around the s So, let me see Nice nice Of inch comma inch is gonna be a List of in comma inch Nice Of x comma y It's gonna be Let's see It's gonna be x plus one And x plus one Is To the east East Okay, and then x minus one Is west West best And uh x comma y plus one is gonna be North and x comma y minus Minus one Is So let's actually make this Different let's say there to hint It's gonna be like this. Okay, so now we're gonna say a east So we want to know like how these things relate to each other Okay, let me see x Delete s nays and then let's just write west x comma y Is equal to This was north So this is nae It's very horsey Nays is equal to uh x comma y Is equal to Let's actually Let's flip the arguments here to dear and let's see Nays of x comma y is equal to map nae to uh east west north south map nae x comma y Okay now Now actually let's uh So let's make a pipe. Let's make it a list of dares place the This one with this one because it actually doesn't actually matter the Order, okay, so pipe is a List of directions And he just connects the two of those directions Okay So yeah, so what might happen here, right? The s So we have the map we have the initial entry Let's just call this part one already Okay, so we know the start. Okay. So now let's figure out The uh the first two attached pipes So then we can say an S and start Nae start and end Is equal to Nae chords a Nae chords Nae's yeah nae's chords So that's just a We're actually gonna not We're just gonna not give us a type for yet So then we can just keep printing out whatever we want Yeah, but then we we change the name here. So we have to change it back Okay, so we got the neighbors of the Okay So that's so the neighbors are east west north south let's actually a Let's see. So how do we check if a pipe is connected? So we got the neighbors and we got and we know that they're east west north south. Okay, so let's check the N in map Coords Okay, so what we're gonna do here is we're gonna see um So see okay. So first We're gonna do uh, we're gonna say where East neighbor is gonna be So first of all, it might not be in the map, right? We might be on the edge And so we don't know if it's in the map or not. So we're gonna say case a mp Map dot bang C Okay, so then we look up the Neighbor see and we're gonna say okay, so look up the neighbor see East of So just if it's pipe axis and it is the case that West a set dot member Exes so now we're gonna we're gonna do it even crazier. We're gonna call pipes a set of directions Just so we can do this membership operate membership Operation quite well. Okay. Let's not again. I think that might be overkill. Okay. Let's just say A comma B A is equal to west Or B is equal to west so then um If it exists Let's see Let East neighbor chord is equal to this We just need to bind it here um East neighbor chord In and then we look it up And then we check if any of them are west And then we just return Just enc Otherwise We return nothing Okay, and now we are going to let's see Corresponding a East is equal to west Chorus Chorus north Is south Chorus Is south is North So this is the corresponding erection so let's This is fd And then we say a neighbor chord is this is the direction And then we just check if a If it does data dot list have like a member Uh a Who will eq lm? Okay. Yeah, we have lm Let's just say axis and then we say Uh chorus D lm Exits and then we do a map f from north to west I think we can do drive In I'm here map I have north to west So why doesn't it like this? 0 to 5 I think it's correct. Let me just check Oh, right I named it m I should really name it map because that's the one I always use A section must be enclosed in parentheses That's just right north south And this is in c and this is and c and Let's go start ns and Let's see a n in map chords non east West north south A non exhaustive fat pattern in function Huh, one of them was Cooresp, okay cooresp. Oh nothing. Nothing. Nothing. Nothing Mm-hmm. Mm-hmm. Mumi Jumala at it again with the Corrections that is correct It was indeed Like that, let me see Okay, it's not working. So we are going to say import Debug that trace and we are going to look at what's happening right here Right now right here Okay, that's it East west north south Didi didi Okay, and Let's We're going to say it. Let's try show A d and x's Okay, so it looks up to the neighbors of start right Ah Okay, and I think I just messed something up at some point and So for north it's getting Let's see a c and c in direction uh, okay, I just messed up the This part this is actually The second coordinate minus one Plus one and then this is actually plus minus one And this is plus one you gotta be careful It's Yeah, okay Now we got the coordinate system working so one One two one and then it's looking to the south And it's getting the fact that okay, so now it could find its neighbors In the map So I'm wondering if I should do breath first search Or like one of them and try and get to start again Mm-hmm. Okay. This is actually gonna be map. Maybe data dot maybe It's just either that way. Okay. So those are the ones in there So that's the neighbors in the map. I don't think you need to search. There's only one and only path, right? Yeah, that's true That is indeed true Let me just uh, let me just see if So now it's a simple loop Let's see. Let's just see What it does on Well, let me delete this trace here So it works for a simple one Example two, let's see What it does with that Okay, uh, just to make sure that it is Doing the right thing So then it's saying a two one And one two But it's saying that this seven here Is also connected, right? And what did we say for the seven? So the seven says that it connects South and west Okay Let me see So then we are so mp So we're going from one one. Okay, and it's saying that one Zero Which is one minus one. So then we're going ah Again, I messed it up. Last one minus one Okay Now it's correct Okay, so now I have this function that finds the neighbors of a given node Okay, so maybe we just pick one of them and follow the The follow the pipe Okay, so let's just see here go so we need to maintain the The current one Okay, so let's go. Okay, so we say a Where ns is equal to n in map e So we find the next in the map c And let's just take a next and ns So we define the next in the map c Okay, and now we want to make sure that we keep going So let's just take two steps at once. Shall we? n prime ns n in map n is prime is equal n in map n prime It's equal to filter not equal to c n in map n I think we need to have like some sort of scene A thing. Okay, so let's see So let's see go start So if I go start and and I can see Is equal to okay seen Is equal to case set.is empty scene of Don't know we are we have to do data.set import qualify data.set as set import No import import That's it set Okay set null scenes over if we were null Then we are we haven't started yet so If set null scene then else set.size scene then Then okay, so the start one is just going to be go and let n is equal n in map start in go n set.insert start scene Okay, and then now we're gonna say um we need to be a bit clever about this Because you don't want it to stop right away, right? We want it to go around the the thing Let's see where Okay, what I think we should do is we need to just maintain the list of Of where we're going or should we Go start scene Let's see so we want to take this Okay, let's see 2.1. Let's say we want to take this one here And then for that one, we don't want to take this one, right? So we're gonna we're gonna say ns is equal to n in map c And filter Not set dot member not so we want to take those that we have not Seen Ah, okay So it's easy actually We just do case ns off If we have the empty list then we are back at scene, right? So then we're fine a so then we want to return set dot size Of scene Otherwise We should have this case And we're going to go and Set dot insert a c scene And let's not make this set bubble up I think this will work. Let's see go Start. Uh, no, it's not the start. It's cohorts a go cohorts Set dot empty non exhaustive patterns in case So this is the first one and then we've actually Then we haven't seen either of them Then we get five Okay, and now let's stop actually printing out everything and let's start tracing here ratio ID What does it do? First it's two of them So which one Did it take let's see trace show ID c as well Oh, this is the long one a confusing one So we started to one that we picked to one and then we see three or one And then we get seven Okay, so it's actually going to be One plus so we're going to add the two of them And we're going to divide it by div two So this one works. Okay, so it takes it around Right, and then it finds the original start again And then it's four example two was not the It's still this one But it's as if it's giving It's saying that the neighbors Of let's have this here to the side It starts at one one, right? So that's correct. It's these the same ones two one one two then it takes two one so it goes down and then it should get Just three one, right? It should just see this one, but it's saying that Uh because it's a type of pipe right so It's not actually so because so, you know, we could be coming from here or here So n in map c Is actually this it's actually case and map dot bang C mapped up Bang mp. No, let's see c mp So we look up the coordinates c of and if it's just start Then we do this otherwise if it's just if it's just a pipe Exes then we do map maybe if exes Otherwise it doesn't have any neighbors Just and then anything Else is just empty list Okay, now it finds the right neighbors And it says four still okay because pipes Now let's do the more complex loop Well That's a And you file example three Okay, and let's Let's do example three here eight nice So where's for the example? Then let's get our input Wow Wow This ain't your mama's input Let's remove the trace Here uh Do Okay, I forgot to save Oh input three i called it Whoops 6768 Let's see. Oh, we did part one Take us an hour. Let's see How long it will take us to do part two Oh, no Maybe its nest is within the area closed By the loop to determine whether it's even worth taking the time to search for such a nest You should calculate how many tiles are contained within the loop How many tiles are closed by the loop? I know you don't like this but There's something called green's theorem which states That a line integral Around a simple closed curve c to a double integral over the plane region d bounded by c A two-dimensional special case of Stoke's theorem What does this mean kids? Well, this is called calculus and it means That to calculate the area of something like this it is enough To calculate the line integrals Around them So we should be able to do this, but I think maybe it's overkill Might might be overkill. I don't know But it's basically this like a plani meter, right? So so it's like this tool, right? You just Can walk around an area and it will It will calculate it. That's kind of cool. Let's see if we can Let's see what we have to do Maybe we don't need green's theorem, but Maybe it's a problem that it's only counting ground here Okay, right The two pairs of dots in the south was nothing like I The middle dot tiles Are not in the loop. Yeah, exactly Here's the same loop again with those regions Do do do do do Mm-hmm Do do do do do do do does it work even though it wants to be zero area When the lines go next to each other. So I think You know, this is calculus um And it definitely works If everything is continuous, right But the problem is right. Let's see be a positively oriented. So first of all, we need to Pick a direction we're going Uh piecewise smooth It is piecewise smooth, right? We just we are going between lines Simple closed curve in a line on a plane Jordan curve theorem Thing is, you know, I did I did calculus I can score And the thing is that we proved these things, right? Oh, yeah, it's green's theorem. That was like a A highlight of one of the courses I took but we never actually Never actually Calculated it But let's see, but yeah, I kind of want to it's pretty cool if we can use green's theorem somehow Dumb So we can definitely get the path So every Jordan curve divides the plane into an interior region bounded by the curve and an exterior region containing So what we all also could do is just see If we can figure out the Jordan curve, right if we can kind of say Uh Here's all the points If we if we have a function that just determines if it's a if a point is within a curve Or a Not within a curve Okay, um Let's see if we can do that. So what determines Whether a point is within the curve Or not So a point is in the curve if a Let's see the input So the point is in the curve if you If it's if you can't go anywhere without intersecting with the curve Right, and then it means oh, but you know, you might go like Do do do do do do do yeah, it does work I think because you can kind of you know The green theorem still works in that Case um So there are There are 12,000. They're like 13,000 points on this curve 14,000 points on this curve All right, we're gonna do it how To calculate how to count Calculate theorem You see it's like, you know using greens. Oh, no Her name not so. Okay Just took a while I don't know what he G to her c2 means Um, so we do is green screen. So since he's counterclockwise already boundary area So what is a line integral integral? integral Sorry about that a line integral For the function to be valid is integrated value along the curve syllable note length I still don't know what you're talking about. Oh Maybe that is What I am seeing So the idea is basically If I remember correctly, right that you just kind of you integrate right so when you're going down It's not adding anything. Okay, and then when you go a If you so that's the trick with this green theorem, right? Is so if you go down Imagine, you know, you're integrating a function. Okay, and you'll go down It's not adding anything, right? There's no area When you go straight down, okay, and then you go When you're going from left to right, right? So this c1 curve Then you are deducting area, right because Because it's So what you're actually doing, right? So you you you add this constant. So you yeah, so You integrate this curve here, right c3. Okay, how much area is underneath c3 in total? And then you deduct the area that's under c1 In order to figure out the area of d So it's quite clever I have to say those mathematicians They kind of know what they're doing So what we are going to do is we're going to go from the start and I think that each if each time We go from right to left if we go from when we go from When we go east Then we add the current height of the map so then we Minus the current height of the map Yeah, I think this will work Okay, so let's see so what we want here is If we can solve this by green serum I will be extremely happy Uh part two So what I'm going to do here is I'm just going to produce the curve Okay, uh, so instead of saying So go see case n as of go and We're not going to return the set size of scene Uh, we're going to say not flip set member scene and in map We're going to map maybe f And a f Is not going to just return the nc. It's going to return the Direction as well Okay, and then it's going to be flip a not set member scene not second And in map is a Let's say in in map Exactly this is the type So an ns here Okay, so and in map is going to return this one and in map Takes in an int and int And returns a list of directions In comma int and in map nice And go Is so now we're going to produce the curve. Let me see. So go cohort set empty go cohort set empty But here we are going to say Go So this is going to be a direction and New cohorts And we are just going to say It was just going to be listed directions that we went go, uh The no go z prime So the curve Ding ding ding ding ding ding ding Curve is equal to uh, let's see Actually, let's uh, let's produce the whole thing because we I think we need the I think we need the coordinates to do the Discretizes I think so what I think what I'm gonna do is just when we go down. We're not adding anything When we go right, we're adding that we're Look at this picture. I'm just gonna do this picture. I think it might work. I don't I don't know if it works But I think it might work and if it works It's gonna be fine It's gonna be fine. Let me Let me see here. Uh No, we're not gonna do input right away. We're gonna see We're just gonna see the uh the example One, right? That's the easy one Print part two lines Okay, and uh, let me Say read file example One we're gonna print it out map m map m Part two Lines and we're gonna print it out. No, we're not gonna map m print dot lines Do-do-do. Okay, and uh, so it's south south East east North north, uh, but it's west And then it's also West Right, so I go south south East east North north Uh west Okay, and now we're gonna say, uh Let's see head of filter, uh And in map c A Is equal to We're gonna have the chords You see Like this. Okay, so I want to add the Oh, Prilla dot had an empty list Do-do-do-do-do-do Do-do-do-do-do-do-do-do Hmm trace show id So east one three So the last one Why is it, uh Let me see. Okay, so any map c just five axis And uh, or just Start just the NC Okay, so now we we we have the full curve Okay, and uh Do-do-do-do-do-do-do-do So what are we gonna do now? So let's see green area Of a List of deer In comma in Green area So if we're going south Um We don't care Here axis Green area North we don't care Do-do-do-do-do-do-do-do-do-do-do-do Do-do-do-do-do-do-do If this works My entire math education will be totally worth it Uh east and this was a Y and X X is a So if we're going east We are gonna Induct He's equal to okay Let's make this a A bit nicer Area A Green area Is equal to green area zero Okay, green area prime zero Where Otherwise, we're gonna get into that situation where we are Back patterns everywhere This is gonna be green area prime of A minus Y X is We don't care about the X here and it If we weren't going west to the left see And we're adding We do a plus Y and area prime Bang A Empty list is equal to A Okay, now Let's calculate the green area That's a curve Or the simple one It says two And why is that it is because And we're always adding We're always adding so we are adding Because the curve doesn't start at zero That is a current problem I think it's because actually a We're not really adding the curve. We're adding the area over the curve So I think it should be So when we're going west we're adding All of what's under We're just off by one What if I just do minus one here? No, I think it's here that I need to do Minus Y plus one Because I'm I don't I don't want to add like that point of the curve itself See because we're only counting this point Right, we don't want to count the Okay, this one So, uh, we went down So here that's one And then it adds two Then we don't do anything and then here it deducts One And here so here it deducts one And then it should deduct again here. Maybe it's just because Maybe I should not have to start in there. Let me see Error empty list. Okay. Yeah. Okay, that's the thing Um, let's do let's remove the uh head. Okay, so we do reverse Uh Reverse and then we're just going to take the tail so we just don't want the The last one you could do this probably in a different way but ever Ooh Let's see that curve again So sales. So, okay, this is one one. Okay So sales one sales three. Okay, so what time we're here So then we add three or not we deduct three so it's Minus three minus so we got minus six and then nothing and then Plus one plus one And then we get this so then we get two Mm-hmm If we're going west, let me see This should be green area prime a yeah, then we're getting minus four Okay, that's not good Maybe we should do minus and plus. So then we should be getting Four no Okay. Yeah, okay this but at least this makes a bit more sense um I think it might be something with a coordinate system It shouldn't matter though. Not in this. It's a symmetrical case. So it shouldn't matter a so Okay, so what we want right is that It's actually this one right so for this one We go here um Let's again go here. Okay, so minus and plus okay, so uh When we go here, we want to add One two three So here we're adding one No, okay. So when we go west we want to deduct so because it's upside down in this coordinate system Okay So I think it's because we're kind of Adding too many so here when we go east We add one two Three Okay, and then when we go back here we want to deduct One so we add one two three And then we want to deduct one so when we go west we want to deduct one And we are deducting one We add one two three But then we're doing it also here Okay, so what we want is a We only want to add when it is a Like a Northeast pipe Uh an east west pipe Because those are the only ones that matter Uh, so let's see here corresponding element um Let's see Because like at the corners It it shouldn't be doing anything, right? You're okay, uh Corresponding element ds. Okay, so let's just write the pipe there as well just the Excess So that's just the curve. Okay For the start it's going to be we're just going to use this in our Calculation Um Map maybe So south south south So south and two point one So two point one should be So this two point one We actually want the pipe there so fd Okay, I was doing it right I wish just not a Adding it here Now we're putting a curve twice So south north south. Okay, that's the one at the coordinate. Okay, then a The green area of the curve Dear, okay the green area Of the curve It's gonna be uh, let's see. Okay, so we're going south south northeast west And here we are going to Need to add another parenthesis and we need to say So here we don't care But here we really do care That it's actually east comma west Okay So let's simplify this and say that It's just green area prime bang a Anything anything Excess anything else is equal to Green area prime a and now the area is two Which is still off by one And it's because we want to deduct the curve itself When we are going Left Uh, which means that here we all we deduct the curve itself And we are going left So then we get the correct area on the curve This is part two part one was just finding The curve a Let's see In the above loop Ding ding ding ding Ding ding ding day No, this is example four Um, and we want four out of this And we're just going to print second You don't want to see the whole curve here Here we get 12 Let's say example four So when are we adding we're adding Here and here and then we are deducting here Let's just see here. This is a comma c at so we're gonna say, um, let's check it out a trace show At c comma We just print c cc a A plus y and here we're doing trace show c minus i one Trace show and then this okay like this Okay, uh, but we're getting 12 and we should be getting four Okay, let's see what is it doing So it goes to I guess this is uh, I guess it's going down And then it goes seven two See let's just print a As well here So we got a seven Okay, so we're here. We're adding one two three four five six seven Okay, and then we're here. We're adding seven again then nothing and then we go Right so here we're deducting five so one two Three four five And then we have a total of eight Then we go up and here We are going east and we keep we we add for all of these. Okay, but we're gonna Deduct that all in the end. So that's okay so two seven two eight, okay, and then You know we deduct deduct deduct deduct I think there's something wrong with because we are Because we discretized it a bit differently. So I think the problem is that That uh, maybe Yeah, because here when we go here, we should really deduct Again Let's run it for example Example one simple curve Then we add one three here Then we deduct two here I think one of these l or j's we should be We should be also deducting So instead of this plus one business, we should be We should just be doing it correctly. Um So we go here and we add one two We add three And then we should be deducting two Because we're not we're deducting the And I think that's correct, right? So we're deducting this with the one itself, right? We curve itself And everything above it This one is correct. Okay Let me uh a plus i minus one and then I And so a plus Okay, let's try that y minus one a plus minus one Then we get zero there, right? Which is not great. Let me see I think it's maybe because um, yeah, so this point Let's print the curve also So go south down And then south and then east Okay, and then we go east again Maybe I shouldn't ignore those south north south ones Maybe it's because um, no, okay, wait So took this north south and the northeast Then east west and the north west Now let's rearrange it. Okay, it's always gonna be It's always gonna come from I think the right So let's say that this one is West north and then we're going North south and then we go south West doesn't go east west So we go south south east east. Let me see Uh, this is the complicated one. Let's go to the example one So we go south south east east North north west west Now this should be one but this one is This one is This one is adding one So this one adds one two three And this one should deduct one two Let's see. So this one adds It's not adding itself. That's okay. So it's adding one two three It's adding one two three and this one should take one This will be one comma two or something And it should deduct two And it is doing that. Okay, and then example four Let's Run it back We go two three four five six times out. So One two three four five six times south We go east East east east So then we've we've added All of these and we've added all of these. Okay Um, actually I'm just I should just do uh, not see here just see Like this just to see the whole thing Um, then I don't need to do this anymore Yeah, the same thing. Okay So we don't add anything Yeah, exactly it course up. Can you try? Uh-huh minus a half and plus a half I can't really do that because it's all integers Let me see. Okay. So it's adding It goes all the way down here and then it adds seven Okay, and then add seven again Okay, and then it goes north twice And then it should deduct and then it goes wait So I got south east and then it goes north twice And then it should deduct a five But it should deduct It's deducting six But it's it should be deducting also when it takes this one, right? Okay, that's the thing, right? So anytime you take an L curve you should also So deduct Let's see if that one works um So when you take the East and it says West comma north It's also deduct Showing the same Exact amount which is suspicious Okay, let's see Go up here And then we should see So we go east west and it deducts And then we go west And it's north uh, it's northeast No, it is west north East east east west north I just did the wrong one It's going east west north Okay, let's see. Uh, I don't see 26 Uh, when it so here it's your deduct Sorry, let's see So it goes a The north north and then west west and that's it. Yeah north east Then it should deduct again Okay, so it it It adds and then it adds So we're up to 14 and then it should deduct Then it should deduct so deduct six Or then it deducts again. Okay, and then it is two so then we're correct here Okay And then we go north north north And then we're going east So it's adding two two two. Okay one two So it's built up a bunch here. Then we go south And then it should deduct twice so five five Wait So then I go to west East west, okay So deducts once And then again when it goes south When it goes south comma east it'll also deduct And we're getting zero in the end. Okay So here we're at Two again We went from six. Okay deducted The zero We go south twice and then we Add up twice and then we go north And here we should be It goes west east west Uh three four five yeah, there is some problem with the Exactly those two cases Okay, let's see. Can I maybe just uh Somehow Just look at the segments It'd be so nice if I could just say, you know if I go in east I'm adding Otherwise I'm deducting But then I get an off by one there And I get an off by a lot there What if I count how many times I've gone north and south? height Let's see I'm going east and west the height is not changing East and west the height is not changing If Otherwise It is changing so here If I'm going north And if it's then it's again it's a comma Don't care North Then I'm going I'm going north it's height minus one and if I'm going south is height plus one And then here instead of doing y I just do h Okay, then I get the same result So then I went south south so about two Then I add two Then I get the same but I don't have the coordinate system anymore That's okay Maybe I can just ignore the coordinates then I feel like we're quite close, but we're just not getting it Exactly right So I go south south and then I add two because I went south twice And then I add two again And then I go up twice. So then we go back to zero Maybe it's minus h Okay, plus one here just h And that was still wrong, right? Minus one here I get zero here I want to go east here It has one and then I go east and it says one And then I go north noise Then I go west it adds deduct one Let me try something here The problem is that I sits in the middle of an area of four a knot On each one by one area Yes, I think it's because like we're we're measuring the area of the whole thing Right This is calculating the area, right, but it's not We're calculating like the contained area Which is not exactly the same Let's just make it h What exactly is this For this for this cube, it's four Because we're saying, okay, this is a cube With length one two Right and one two. So the two by two cube Has an area of four Okay So that's exactly what we're calculating, right? So it's a two by two cube with an area of four But it's not actually a two by two cube, right? It's actually Um So I think I mean green serum is we're doing green serum correctly here But we're not doing we're not exactly doing exactly green serum So let's uh, okay. Let's let's make it floating then float and then let's add Minus 0.5 Okay, let's see So you wanted to do um Okay It doesn't yet. So it doesn't work out because it's uh, it's not it's discretized, right? So So these columns here are zero Right I have tried okay Making it float didn't help Because we weren't using it. Okay So thank you like the area of this cube here I mean it's doing the right thing with the area. It's just uh It's just saying that between So between this one and and this one, right? It's giving an area of one. Whereas it should be zero between those Because we're saying that it's like at the edge The intersections, right? What if I um, what if I do minus one every time I go? Right that also doesn't work when I add So when I work I south Yeah, okay. Green serum does not work out here Sadly because And I think I said this in the beginning Because it's not a continuous space, right? It's a discrete space. So green serum does not hold Quite sad though, it would have been very cool if we're going to just looked at the curve um So I can count how many No, I can't just count how many non-segment parts are above right because uh Like with this one, we're also counting let's see See here We were also because we also we're not just counting ground right we also count We count tiles not in the loop Could I maybe do that? Let me check a Okay, so we have the We have the curve Okay, uh Now we can say curve a curve set equal map dot also set dot from list Map second curve Okay, that compiles So I just want to see a okay. Let's say ignore north and south So let's say we ignore. Let's just erase this H here. It doesn't work because we're not We're not gonna use that. We don't need to erase it here as well Okay, so whenever I go east I want to say Points where points above is equal to This is gonna be a map a y y to y comma x on a zero to y Because I know we're gonna erase this trace show Now we're gonna erase this trace show We're erasing all the trace shows. We're not gonna care right now Ding ding ding ding So points above is it gonna be a list of points Non curve above is equal filter set dot member curve set points above Set dot member a flip known curve above Okay, so this is actually points above set dot from ask list of this and So non curve above is actually Points above set dot difference A curve set So we're gonna say if you're going left you will add a set that size on curve above if you're going to the Right, okay And if you're going to the Left We're gonna deduce deduct Then we get one and four which Is the correct answer for this one But it did take a long time. Let's see With the example five Here we want 10 Example five Do do We get minus 11 That's not good I think it gets messed up when we have a Stuff that's not on the curve Let me see Example six Minus five Figured why you have time to search for this I calculated the error within the loop Are you sure it's not correct at least try submitting Yeah, I don't think there are It doesn't work like that Okay So then it worked for it works for the trivial examples, right? But here there's one that worked when we went east to west west to east But uh When it doesn't work When it's only counting All right It works here because here it like it's going east to west and it kind of Uh Maybe it's because the list is wrong It's about if you had to add or subtract 0.5 out of 3 So subtract from west if it was a right or left corner before in the loop Then it works out You're saying the original part works out if we add 0.5 When we take the corner and deduct 0.5 when we move the corner Have you tried it? It might work actually because then it accounts for these Half areas But that okay, uh Okay, let me then do that We're undoing To this height thing just gave us the same stuff And it makes sense because we were actually you know, we were looking at the Let's now Let's work out the cases. Okay a This is northeast This is going from the north to the east this goes from the West to the north this goes from the this goes from the This j go from west to north. Let's see again. Yeah, I'll be with country to be forward Connecting north and west Yes connecting north and West south and west and south east Okay, let's Flip this function To just get the pipe type right pipe type okay, and Let me see. So what I want to do now is I want to Like this And then I want to They and I want to This and I want to do pipe type pipe type Oh, this was s Okay, uh, so l minus is Plus y minus 0.5 Okay, let's see how it works out So if if we're we're not going east to west then We don't care Okay We're gonna not gonna trace it right Now we need to say Five and we want to print Number six Okay, and uh, so what we want now is A minus y Let's see. Okay, so this one is just plus i minus one plus Minus i plus one Okay Let's just see here. This is P and we are gonna say a green area a a plus Delta Where delta equals case pipe type p of So here the delta is um Here delta is y minus one Okay, uh, so we're going then we're going east and we want to Add all those okay, so and then if we're going east And so if we're going east It can't be the case that the new pipe is F right It can only be j Because we're going coming from the left and we're going here the new pipe has to be Uh connected to the east so uh, okay Yeah, it has to connect to the West right Yeah, so we're okay. So here you want to say it's y minus 0.5 No, okay So this is not exactly correct. I think because we are going to be having So the like one of these is going left to up right and the other one is going left to Is going down This is a nice format. So this we're going to be L and f Okay, l and f and this is going to be a minus Delta Let's just see if this Compiles green area is complaining about A any expression Right non-exhaustive patterns in case a yeah, it's something here pt I think it's because we go to the start um Right, so if it's Start then just from integral Why I think Okay, uh, so here start actually is Uh The f so here it should be Plus 0.5 And then we get exactly one here Now here s is also like this, but the In order not getting the right ones, we're getting still minus Yeah, we're still getting a lot of minus here 2 2 2 2 2 2 2 2 0.5 I mean it's working out for the first example. That's true, but it's not working out for the Other examples Mm-hmm Okay, I'm gonna take a two-minute break And uh, because I gotta go to the bathroom, but I'll be right back. All right. I'm back. Anyway, uh green serum does not work for this because it's um It's just let me just Yeah, it doesn't that doesn't work. It's sadly Let me go back on it and see how was it And day one So the thing is that it it works for um wipe type Should not be play here Mm-hmm. So this is the correct implementation of the green serum one, but it's just The problem is that That we it doesn't just discretize correctly So let's uh, I I'm gonna switch to a different approach. Okay I'm just gonna figure out a Which points are on the curve? Curve set is equal to Set dot from list map second Curve Okay, uh Strange also that this green area thing here. It just doesn't work Um We're gonna find the curve set These are the points on the curve And now we're just gonna find a point that is definitely not on the curve and just check If they can be reached Just check if they can reach The outside right? So to do that, uh, we just do the set. Yeah, like a flood fill basically. Yeah, exactly Um, so I'm gonna So if a point can reach the outside So we're gonna take the total amount of points and so we're gonna take the Points minus the number of points on the curve Minus the number of points that can't reach the outside. It's gonna be the Uh, it's gonna be the Yeah, so that's gonna be the total amount and Um The trick is that So you don't have to check if a point reaches the outside. You just have to check if the point Reaches any other point that reaches the outside, right? So let's see Um So now we need to just figure out What points how do you how do you see the point can reach the outside? Let's just see so if it can reach the outside if it can reach the If it can reach the edge And it's not on the curve Okay, so let's see here edge points This is gonna be um sip Let's see how many points do we have Um We have the map We have the strings Let's say So max i is equal to length of strings Max x is equal to Length of head Strings, let's just see what max max x max y I'm doing second. Let's just see. Okay, and four five six One four five six. Okay So there are 2010 four five five and this one is four five five So it's five and five so one zero two three four Five so the max x is gonna be zero come off four, right Okay, so a Edges is equal to It's a At one for one it's gonna be all the zero y's x x from zero to max x Uh And then we're gonna have the max my comma x zero to max x and Then we have the other case. It's gonna be y zero zero to max y I have to delay this x y then max x Okay, and then we're gonna do set dot from list Okay, and the trick is is that it's these that are not on the curve That's gonna be our initial set dot slash Uh curve set Oops now, let's just see what the set size of the Size edges I'm not gonna print the curve Okay, so there are 20 edges here, which I think makes sense. Let me see one two three four five six seven eight nine 10 13 15 so we should be 16 Uh, yeah, it's max x minus one because max is actually it's like this okay, and uh 16 I like the green's idea and it nearly worked but I feel Phil can also travel along parallel pipes Yeah That is true. Uh, yes Uh, this is gonna take a while, isn't it? We're almost nearing three hours now. So I think we We'll call it a day for now Then let's just see to do implement flood bill Make sure to check Let's take that this exactly this example here So we want to make sure to check example seven and Right, so you might have a point that's uh Let's say this last line wasn't here, right? and then It would still they would still be outside, right? I still feel like Yeah I don't know. I feel like the the green idea it should really It should actually work right But the discretization is wrong calculate the area, but this Station is somehow wrong Maybe yeah, I think I'll think uh, I'll think I'll call it a day now and uh We'll work on it tomorrow But I think maybe we can try a little bit harder on the green idea because I feel like that that that's how you should do it, right? Yeah, it's just that there's something wrong with the Like uh, oh we should like Uh-huh Because you know because there's one curve. That's like the outside Of the curve, right? Uh, so maybe we can just calculate a couple of green Green areas, right? Um, and that should account for the difference between the three I feel like it's possible Green area calculates a green area, but the discretization is somehow wrong So what if I calculate you know, I calculate here Like the area of this cube and then I calculate the area of the cube that's uh shifted somehow And then I deduct to or I or I do something like I assume that the s is in The pipe thread 0.5 anyway Let's call it a day for now. Uh, we're finished with part one quite easily We're still working on part two and we I think we have the right idea, but we didn't quite get it to work So we're gonna call it a night See what happens tomorrow And hopefully we can make it work But thanks for tuning in Sorry, I couldn't finish it But that's how it goes sometimes All right, thank you for today and See you tomorrow where we will Try to finish this and then do the next part. I think All right, good night