 All right, welcome to today's stream I'm waiting for some feedback. Yeah, I'm not essentially it So I'm gonna String open. I thought I would be working on it right now, but I haven't got the feedback So I'll just do a short stream meanwhile. Hopefully it's not too hard today And if I do get feedback, well, I have to kind of have to change back to it. So But we see if we can get things done All right Let's see you all three jacks okay, but also getting in Many problems all of the coverage high tones Okay The cannons were large a very low ceiling quick scan chatting density was a map risk level Okay, it's gonna be another it's gonna be another and Graph thing I think we'll see Let's pipe their read input into print over a task one Now what is the input? Read input File path to a list an IO of list of listed It's read input equals map Map so this is a digit to read D We just read it. We add it to make it into a list Lines We now we map this over the lines. So we have to have this over Read file How's everyone doing today? Right. Okay. So we have this We do want to map the map Over the lines And then this one we can say how are we? I was up to two working on my thesis, but it is looking good But I'm waiting for feedback So we'll see if I have to fix it even more. I Don't think so, but it will work out Have you tried today's task? Okay, so we got the risk level and Start on top left position your destination is about my precision camo diagonally Now each position is a risk level Add up the risk level of eight branches at your enter That is don't count the risk level of your starting position unless you enter it leaving it as no risk to your total Your goals to find a path with the lowest total risk in this example path of the lowest little risk is highlighted here What is the lowest total risk of any path from the bottom left to the bottom right? Okay Wow nice Okay, so this is gonna be a graph algorithm Let's cheat a bit. Let's say. Let's look at what we did. What was it day? Day 10 no day 9. I think it was day 9. Let's see get a I have another tool actually called bat L Haskell day 9 day 9.HS Because I had this nice function to Generate the neighbor list, right? Copy copy this So task one list of int to int That's one nums equal where Is not as good, right? How long did this one take you? Was it hard today or oh no, okay? Let's see. What do we skip for the end map? What was the type of the end map again? I need to import this one. I think it's a like a list of ints and A list of its neighbors, but I I needed I need the coordinates right look at this Say I had a map with the coordinates as well. So I wanted the indexed one, right? Okay, so I just copy this one I mean It's not really copy paste if you're copying from yourself, right? We just don't want to be We don't want to get okay, but So this is indexed So we add an index, okay, and then the end map Exactly, that's going to be a list of list of ints with a list of ints and the LPs Where So don't need this one Don't need this one. So I think I think the let's print the end map here copy pastry factor and hello Jello Well, you got lost in the path finding I'll go right Let's say see what happens to us Ght 0 3 day 15 and time Day 15 okay, so this is the path and I think we can take the end map and we can So I want to I want to make it an actual map Okay, so End map map is gonna be so you concat the end map, okay So then we get the This one now I want I want to modify it a bit okay, so So map So it's gonna be a pair so chord comma value and ends Right and I want this to be a chord comma value comma neighbors and then I want to map dot from list now this is gonna be a map of int comma int to the a Value and For the neighbors here. I actually just need the cohorts map a FST So now it's gonna be a map Okay, so And map and map map That's just gonna map and two of the values and the neighbors so one has a The value one and neighbors zero one zero two Okay, so the goal is nine comma nine Okay, so let's write a Bfs. Let's write here at a type edge graph I Think we can probably use data dot graph your data dot data graph Let's see See what we have here graph from edges Identical to graph from edges so this takes a node Mm-hmm. Yeah, okay, we can make this happen. Well, this is gonna be our So let's not have this so we have this We make this into not like this, but actually we make it into a V comma see and Then a list of keys. I think there's a syntax error. So, yeah, okay, so this end map map now is It's now a list of ints and a key and a just as a graph, okay, so we now import It did a graph graph my guy graph import qualified data dot graph s as graph so a How does it work? We do graph from edges. We get the a graph We get the a so note from vertex and vertex from key. Okay note from vertex vertex from key of graph dot graph from edges And and map map, okay nice So we have the okay, so spanning for its okay, I Wonder if there's like a way to Okay, so does it actually help to have an actual graph? Let's look at who go Okay, so here we have a BFS Okay, let's just implement it then So we will say Bfs now What is the type here? Takes in a graph It takes in whatever this one graph comma it takes in a What is the type of graph from edges? Or so this is odd key. Okay. We're gonna say Or or or valve or key To And then we take in the three functions as returned here I don't think we need all of them Let's just say or node okay, so we do this and Okay, so breadth first search Starts a This is not actually breadth first search and we're implementing dykstra extra Which is just a better search with my priority queue or something like that Dykstra And we take a key And we take another key and we return List of keys Okay, let's see. How do we do this? jik jikstra equals Okay, we have the Right, we also get the graph, right? Yes. Oh, yeah the graph we get the node from vertex and vertex from key We get the start and we get the Go do we just maybe use the keys Okay. Now Let's go Jike dykstra dykstra. Oh my god. I what it won? dykstra dykstra's algorithm Okay, so we have the Create a vertex at Q for each vertex to be in graph So we have the distance to we use to infinity and then we have the Yeah, that's a brave the one and then we add it to Q and then we take the distance to the source I Think we actually need a Need the num It's not enough to have the We had the num node here, okay Okay, so we get Where V set equals Okay, now we're just doing the Okay, this only is a search pass you can turn to search at line if the fish in this target. Okay So V set so we have the But this should be here, right? Okay, doesn't I don't think this works Because this is a custom graph definition Okay, let me check our feedback so a Let's see we have the vertices This is not the best way to do it, right? I think it's better to do it with a Okay priority Q. No Let's do it like this. Okay the from start Don't we need something else right you need like a semi group we do have a zero semi group Okay, we don't we need a it needs to be a monoid Okay, monoid noid Something like that and defined Okay, uh set from list V set All right. I need to do Actually, I don't need and this doesn't need to be a set Okay, I can be a Okay, so D from start is just the map empty Uh accept Right, so we have the vertex set for each vertex at this Okay, this is actually a Map dot singleton Uh, okay, so this one here should actually be a Vertex and this should be a vertex map singleton a start Start empty. Okay. I think I need the scoped type variables Okay, and How do I refer to the type of the node? Like I think I can just have it inferred But just doesn't know here What the type is yet Okay, so let's just check Okay, so let's let's write the loop Go Vertices V Okay, go Okay, and then I need the current D, right? So go has type Go starts with map dot Singleton Map dot singleton start empty now So go. Okay, so Okay, go D from start is false Uh, but this one actually doesn't give us the the current path So we we need the D from we need to do from Start and parent so the parent is gonna be like this, okay Go D from start and Vertex in queue with min dist Okay, I need the graph vertices graph No, okay, so this one is gonna be like this. Okay. I think I'll think I'll do the priority queue version better. Yeah So the distance from start is empty. Okay create vertex priority queue queue Okay, so for each vertex in the graph If V is not equal to stores, we set the distance to infinity and the previous to undefined So this is the dist And this is the parent Okay, and this is the pre queue Now we initialize it by saying So we added all with the priorities of infinity Okay, now we need the set algorithm Now we have the map So we so we have the distance and we have the parent Do we need to iterate over all the vertices every time? Okay, uh, let's just do that. How do I efficiently find the minimum? Yeah, this is this is gonna be a bit of a mess, right? Go, uh dist Look at this parent Uh, I don't actually need these I think I'll I have to start off these With the infinity Okay, so it starts with uh off with this empty. Okay, let's see And let's see Okay, so first we We say that the Keramin is going to be Um data dot map Data map I think we have like a find min function find min That's a minimal key in the map Okay, so let's let's I think we have to do it the different way So we're kind of using a priority queue So this will be a map singleton empty And the list to start So these are the ones that are uh, it's not a map. So we find the Less smallest one And because if there are multiple we just have to um, we just have to do it again. Okay, so current min It's going to be current min Okay, and uh Gonna be find min. So this is gonna be delete And find min A dist Okay, uh, we are going to um insert The uh, okay, we know that these will always have a key. Let's say that Okay, let's say it like this, uh How are we doing this? Okay, so this is the uh min dist Uh Okay, so in Yeah, okay. So this is the min dist nodes and then delete and find min dist equals Nothing, let's just say that This is a map dot delete find min This empty here So I would you cannot figure it out yet So we're gonna we're gonna assume that this is always gonna be Has a node Okay, what is a node? So n nodes And it doesn't like that because oh, uh delete and find min right, okay Min dist and then Then this is no min Okay We're gonna do a bit of like parity like programming. Okay, so we have the no min and the min dist so then we're gonna say a We're gonna say so this is gonna be This is a nerve tech vertex Okay, so I have to Get the no. Yeah, okay V Yes This is gonna be the node a the key and the nays And as the neighbors is gonna be Node from vertex V Okay a Okay, now I have to check Uh So we're gonna Oh, this is a minimum distance And we had some more there Yeah, I'm not sure this will always work because the mempty might not be like that. Okay, but we have the The node the key and the Neighbors And this is a list of vertices Okay, um, we're gonna say here, um N vs is the map Maybe Maybe vertex from key ns. Okay We map maybe the key from We have to import that as well continue on maybe Okay, and then we have the neighbors of that vertex Okay, and so the trick here is that this is the minimum distance we've seen so far But I can't I think I don't think I can do it this way Let's see Because I I have to kind of remove them right that's why it has to be a key map of key to Map of vertex to a Let's do it that way then. Uh, it's gonna be Map vertex start Mempty And now it's uh, I think it's a list So I delete and so now I can't delete and find them in anymore We're starting to do it with like a priority queue, right? I heard that the one where the function type signature goes naturally Yeah, I kind of like that But now we we can't write it because we don't we can't specify these we have to have it inferred Let's see Let's just have these as a Can I have like I have can let's have it not yeah, let's have it Uh Founded note as well Okay, and then this is a map So it's map.insert Uh, what is it? We say map.insert And we're gonna say a start a mempty On map.fromlist A dollar zip and we're gonna map over the the max bound Of the over the graph dot vertices Make tuple sections for this Uh, so Init dist equals this Okay Init dist and parent Let's say the other component here the parents Is gonna be map.empty Okay, uh, so we do the initial distance. So this is uh, this finds the This is the initial distance of all of them But with the one set to zero So while Q is not empty and then okay, we have the Set dot from list graph dot vertices Graph Okay, now this is gonna be the Q Q set Vertex in Q with mint is U Okay, I don't think we actually we don't need bounded here So, okay, so this is what we're gonna do We need the monoid node here and or Okay, uh No, I'm still writing that extra one It's a bit it's a bit tricky, right? So we have the initial distances That's just gonna be map single to start empty Now, okay, so how do we find the So how do we find it? So while Q is not empty So we have the we're not gonna have this set It's gonna just gonna be graph graph dot vertices a graph Okay, so I have the V's So actually if I have an empty here, I get nothing Doesn't matter what these are but go this parent If I have a V's This is equal to find Min What can I do? sort by Okay, so here I can take a two I can take a node a and b and I can say so A D sort so this is this sort and so D sort a b Uh dist D sort dist a b, okay, so if just a A Is in a So if a has a distance We do a a map dist And b has a distance just b a ad bd map dist Is equal to a ad Compare ad bd. Okay. Now So if just a If it's only a that has a distance Then we say a map dist Then as if it's just A that has a distance then a Compare a and b should return less than because it's less than infinite Otherwise, yeah, so otherwise Otherwise b map This is gonna be greater than And if neither of them have a distance it's gonna be They're gonna be they're both infinitely far away. Okay, so this is gonna be a I mean, this is this is not efficient because we're sorting all the time, but it's not good Hey, okay, so we have the by dist. Let's say So by dist here is gonna be This is the the vertices um But we want the distance parent and then So craft dot vertices of the graph Couldn't expect it type actual type You know, see Things in a graph, right? Yeah in the list of vertices So go here is a A Oh, yeah, we can't define it yet I think this should be Oh, no, sorry This should be this b dist b Okay, now This is Indeed a list of these. Okay, so any this is a map of vertex to mempty And we look up a and b and we look up a and b. Okay The sort by dist This is gonna be so these are vertices, right? Let's say it was just Envys Okay, so let's constrain this. Okay D sort Now we can't So we can't mention the monotone type Because it's not in scope So map takes in a map and a key and returns maybe a yeah, okay? It returns the maybe a Now these keys here should be vertices and these are the Oh, yeah, these are the Well, these are the keys. So these are the vertices. Yes Okay, so this is the smallest and the rest By sorting by dist Okay, so we've come to one with the mint dist. Okay So you remove This is gonna be q Okay, and now this is gonna be q prime And then we say for each neighbor v of u still in q. Oh my god okay, so ns is gonna be a Okay, so they note the a Key we don't care about the key and the neighbors Is equal to note from vertex s Okay And we have the neighbors Okay, and so a A ns v Is equal to map maybe Vertex from key ns These are new vertices And q Okay, and can we just do like this? data.set Because I don't think yeah, because they yeah, we don't Okay, so we say a q prime set You said prime is equal to set dot from this q prime Okay, now we take the new ones and we want the ones which are For each neighbor v of u still in q a n in q is gonna be map maybe and then filter map dot member You know set dot member flip set dot member a q set prime Dollar, okay, so these are the ones still in q okay, so the the Distance Okay, so now we have to find a s So now we're talking about a u this is gonna be u U ud is equal to A map dot okay, so we're gonna say case a This map bang u of a just If it's in the map then the the Okay, let's map map over this list Now we need to update the folder and prev And in q okay, so now we have the new vertices Okay, so now we have a Dist prime prev prime You go to folder f You hide this and prev a So folder and f and then we have the n in q Now folder all right, we want a Okay, no, it doesn't matter Well, it doesn't matter. Okay, so we have the b and the t and a A dist here Oh Okay, so let's call this instead of calling it parent. Let's call it prev what's the delimiter so map Uh This is the it's to look up in a map, but like I mean so we could write like this, but then we don't have it scoped And we yeah, so we look it up and if it's there we get just something if it's not there we get something else Uh Loop where loop So loop and uh, we have the We have the dist and disc and prev Equals Okay, so for the loop Okay, all equals a Dist of u plus the length of u comma v right, so that's the length of u comma v It's exactly a A node v So we don't need the v here. I guess so we do first here Okay, we want to say just a v d and then I don't care about the key and we say We don't care about its neighbors. We'd say Uh vertex No, sorry, this is this is uh, okay, we always get this where uh So vd comma. I don't care. Don't care It's equal to node from vertex v because there's no Use word a zero pepper. Okay. We haven't used it yet Uh, so this is um We get the the node and the v and the key Okay, so the alt okay, so Ud is equal to Didn't we already find that? No, yeah, okay, so ud Just ud this is gonna be we're just gonna say just ud here because we we should have We we have seen some of the graph before just ud We get just ud. This is gonna be map So we can just say ud equals map It's gonna be this map U Okay, so we have all equals a ud The u distance concatenated with vd Uh from the context of monoid Oh, yeah, it's called U ud map and Vd, right? What is it telling me now? could not So this v here isn't Ud vd is a node node from vertex v Right, it doesn't know the type Uh, so this is gonna be node What does it know here that uh Now could match node one with node because Damn it. Okay, then let's just make this node then an int We need to know the int It's a bit sad, but Okay, it's because we can't uh Assure ourselves that this is actually the same thing node from vertex, uh, and Could match expected type maybe a with actual type. Okay. Oh, right So it was maybe okay. Let's see node No, I guess that one worked. Okay, but this these sort this could not this dude. Okay. We need or node as well Okay, we're still in the business Okay, so alt is a node Okay, now if So we say a case alt less than Uh, this to be Vd equals map that insert V a Alt dist comma map dot insert the previous one print me map dot insert v a you Rev okay. Now we've done the loop and we fold it and this is the disc rev disc rev Then we just check a case a Goal Just V a Just D is the a If you look up this map Goal We don't need we don't need the path. I don't I don't think we need the actual path We just need the maybe node So if just D isn't a disc goal, then it's D So if we found the goal and this prime I should say otherwise disc prime rev rev prime A And now it's not happy with the vd map dot insert Alt is a maybe node. No, alt should be a node. Why is it saying this so dist here? Or a dist Is a map of ints to maybe nodes That's not true So alt here is a maybe node Which is because it just thinks that ut is a maybe node and ut is a maybe node because it thinks that This this may be this And it thinks it's all right Just D Okay, I think we have dykstra down So if we found it we just return the disc otherwise Let's see main task one. Okay, let's do task one. So we have the graph So let's just run dykstra No, I always tell me to run dykstra Let me check for feedback. Sorry So he says he looked first thing tomorrow morning Okay it's due at nine oh Nine in the morning though Okay, let's just see if this works dykstra on Graft or graph from edges and And map map what happens if I compile this oh main ports itself Why do you do it like that? Yeah, and I need to start and look finish. Okay so, um from just Vertex from key 0 comma 0 And the goal is from just vertex from key 9 comma 9 9 comma 9 And it's saying yeah, this should be maybe it What is it complaining about? No instance from monoid int. Oh my god instance monoid Int where? empty equals zero instance semi group Int where? non exhaustive patterns in function loop Oh, yeah, okay. So if it's not there In is not a key in element in the map Because without d sort by dist. Okay, let's try show this actually I don't think it will show us anything because these are vertices That might be an issue. Yeah, these are just the vertex keys and say sort it equals Okay, I need to show node. I need to show key I just want to take the Okay Show ID What do we get for the vertex there? Okay, we get one zero zero zero one. Yeah, okay. That makes sense. Let's see Okay, we sort that by distance. Yeah, okay. Let's go back to So we get the minimum one. Okay, and then we get the zero one Okay, let's uh Let's see What is the dist prime? develop so after we should get So we get the distance to zero is zero So then we get the one and then we get given map is not an element in the key Let's just be greedy here and say Like this, right, so this should be dist u, right? But this is okay, so we have u vertex with minus two yes to h river v of u still in q Yeah, we get the alt at this u and the length from u To v We don't necessarily know that right. We don't know the length u to v. Oh, yeah. Okay. Yeah, so it's the current It's the current neighbor and this is the length. Yeah, okay If alt is less than v d then this v is equal to Oh, thanks for the follow Oh apricot reading That's cool. We're really really trying to Hey We're trying to implement this What it's giving us Um Okay, so let's say a u d so let's go look it up here and then you mb u d hey all So mb so u d so, okay This is alt less than v d. Ah, this is not v d, right? So this is a So, okay, I figured out so this is u d Okay, this is yeah, okay. So this is we go back here. So this is supposed to be u 2 d u 2 v, okay Now and then a halt Is a this u U d plus u 2 v Now we have the a few cases here Okay, so let's just write here. This is the A update equals This no update equals this comma prep Uh, so If alt is less than the distance A so first of all If we have just v d A dist map a V n Alt is less than v d Then update Okay, so uh, so However, yeah, so if if either Yeah, so this one is otherwise. It's no update. I think it should be like this Basically, we should always Update so we get nothing Let me see. Okay. Uh, this is gonna be l this l prep, okay, and then We look up in l this we insert into l this we insert into l prep. Oh no update is l this l prep, right l prep Why do we end up with the the Show the Nothing Okay, uh, we're always showing the note from verdict. We're showing the one we're looking at now Uh, but this one is actually just uh, we don't have anyone left It's a dist map Go actually But it's saying that this is always from this zero zero It's like it it's like the d sort that this is never Dist prime because we fold r With the loop Let's check again. So if Alt is less than Okay, so if it's less than the up then we should update If v d just not exist then Okay, so if there are actually there's two cases here, so we have that If we don't have the distance It's update. Okay The other case is that we So we have the distance and then If alt is less than v d this is equal to update Now if we don't have that if we don't have the distance Um Then we should update Okay, so if if we we have nothing Okay, so no and then again like this So we have the distance and the new one is smaller than we update if we have a distance and the new one is Larger than No update, but if we don't have the distance Uh, otherwise it goes Update so that means it's infinite Okay, let's see. Okay. We got it. We did it We implemented Dijkstra threshold in a Haskell graphs That's it That's not bad Okay, we get just 40 for the example, which is correct. Now. Let's do it for the input But we don't actually wow. We don't actually look at the path Let's see a We could return the path We get just 42 That seems a bit low, but okay. Oh my god. Let's actually return Maybe a distance vertex And then this one will be Let's say a build map A ft a pram But we didn't solve it, right? Didn't we just uh, it didn't work So how do you do the build path build path f from to prev? Okay Is it gonna be a equal to bp prime empty Where okay, so we say a bp prime a Kerr path a Kerr node a t case cn equals equals t is a we add the Kerr node to the target and then we We add the Kerr node to the Kerr path And then we reverse it A We it it's just this now bp prime a cp cnt a case Because now cn is not equal to t Then we don't we need that t still. Okay, so then we say just a Just a and next node A prev And we we're looking up a cn map prev So if you find it Then it's a bp prime a cn nn So it's a cn a cp nnt We don't need the t here Because we already have it And then bp this is going to be What's the current path? Yeah, yeah, okay What's a bp prime one score one score nothing I can't find it. Okay. What's the wrong with this one? Can I start in 20 type? a No, sorry, it's prev looking up cn now a Go becomes filled path a built path prev start no build Start goal build path prev Okay, this is going to be if we find it. We're actually going to say here build path a We're gonna say a dist map a goal Now we build path a path of the goal. So this is going to be Maybe a Maybe no Maybe Maybe vertex. Okay here. We do just t build path start goal prep and what's wrong with this one Uh, all right So what does it return? Oh my god couldn't expect type maybe int Right So what does it give us for the path nothing? Okay, so the the parent Of uh Is you okay? So and then I so I even started v this Okay, uh, then I look up the goal And if I find it I return just t but then Build path. Okay. So if I am at t just reverse. Okay. Otherwise, so look up The current node and concatenate it. I don't think I'll be getting any more feedback. I mean if it's due at nine in the morning and I will get something from someone having a look first thing tomorrow morning like I might get some feedback What are the chances of me being able to act on that feedback? They are not a lot I tell you what is going on with the prev here I inserted we had to do it with the prev prime No, damn it. What is prev prime here? Okay That sucks to me right now. What do we do? Because I implemented the extra right It's building the path My build path function is not giving the right thing All right. So here I actually have to start at the target That's how the build pass should work But this should also be with prev prime. Nice. Okay. Now. Let's uh, we have this built path Now, let's say we say V comma P is equal to Okay, so we print V and then we do a map Map may be now we do load from vertex A map load from vertex Over the P right and then we want to pick the key s3 F uh K s3 Dot not over exactly. Why does it do that? right We want the chords Use on the feedback right and then We don't reverse it because we started at the last one Okay, so it's a goes a So it goes a zero zero zero one zero two zero zero zero one zero two And then it goes zero one one zero one two three four five six Zero one two three four five six And then it goes down one and left one seven three seven four Let's see so a Okay, let's um Let's say print P Indices equals a conkat map first over indexed this is going to be a So conkat map conkat So indexed it's a list of lists, right So if I say conkat indexed Then this is going to be yes Map is the conkat index. So this is the indices now um print path Okay, so this is just map map first over the indices now a path to str So here we have We have a list. Okay. So if we have the empty list, that's the empty string path to strings we have the p and the C's We don't care about it here. Now we have p And we have the empty list and the rest We want to say path Equals a slash n On path to str No, it looks like this. So we have the empty list in front of r. So this is going to be a um Path to string prs and otherwise it's gonna be So a otherwise we have a c c's it's gonna be a if a c set dot member p Then x x concatenate it to path to str a csrs p Okay Now these are redundant brackets Okay, so this a p here. Okay, so, um, so this is actually going to be case and Just p to str p cs This is a bit Okay, so, um f or this okay like this now I can say To stir it's a bit dirty, but I will allow it In this c comma p. Okay, so we get the three down and then we go like this And then we go like this and there's like two here. Yeah And the two here and then Like here And then we go all the way down. Okay, so we get the exact same path Let's see what happens here Oh Right Didn't we set the goal to be nine nine? Yeah, so we want to start at zero zero Right, okay start equals zero comma zero and equals length A What is it? The x is the a Length of head of x comma length of x nums Let's say a nums at fm So this is going to be a length of a fn minus And this is going to be The length of nums minus one So and then this is going to be from just where it's from key start And it ends at the end Right, and then it should actually now it takes a lot longer, right? So what was happening here is that yeah, it found us a path Uh two nine nine But it didn't actually Go all the way. Okay, is it going to be Oh Maybe I don't need to um, yeah, I'm yeah, I might as well maintain that path Okay, 46 seconds I'm getting a nice path four hundred and ten Nice. Okay. We got the first one God damn it. Okay Now that you know how to find a low risk path in a cave you can try to find a way out Now the entire cave find us larger both dimensions than you thought Yeah, oh no Your regular map tile repeats the right and downward each time the tile repeats to the right or downward All the risks close on one level higher than the tile immediately up or left of it Let's say let me just check one thing. Um If I just don't if I just don't ignore building this path Is it still slow? It's a nice path though I'm digging very generally right. This is like dykstra for general graphs It is probably not the best though Because it's like it's probably not gonna fuse or anything Let me see Let me just change. Okay, so this one didn't help Okay, so this is general dykstra Okay Now let's say a int dykstra int dykstra Okay, so this is not going to be a node anymore It's going to be an int And we return maybe int Okay, now this is going to be A Right, so let me just yeah, okay So this map here can actually let's go let's optimize the first one first So this map here can be import data a modified Int map as I am Okay, it's data dot int map data dot int map so This one can be I am Let's call it imap and this one is an int map And then a You can do im I map and then we do I map I map I map I map I map I map I map The dsort takes an int map and key key to ordering and this is also going to be I map And this is going to be I map Let's keep building the cast Because we do a lot of lookups in that map, right? So it might as well be as fast as possible That's probably What's probably the worst here is that this a sort by q dist Is going to be the worst That's probably this sort by here is the one that kills us because that's the one we used to pick the smallest one Because we don't actually need to sort right. We just need So what is this q here? It's actually a list of keys It's quite a little bit faster with the imap Okay, this is a list of keys and Now we just need to Take it out on a list. Let's see. Let's just do There should be a He's gonna check Because we should be able to do this faster and This is a list of keys Because the only one that can change is Is this yeah, okay to put all of them can change right? Yeah, okay Do do do do At least this one should be This can be oh wait. We can we can fix this actually Is this sort from ask list? Because we've already sorted the list so we know that it's gonna be ascending. Oh, but no, but it's not the actual It's a different kind of sort Okay, yeah Shouldn't it be like a you know, we have like minimum buy But we don't actually get the the index Probably minimum, right? Which is the one we would want and it's because yeah It's kind of it's a bit hard right because the measure keeps Changing Let's just do this So minimum buy Like right, okay because i'm returning Use minimum buy like this Q prime This is gonna be Let's do just set dot from list Okay, let's actually just keep this as a instead of having a little list Okay, this can never happen. I think well now here we say just say q case Set dot now q just delete And now this is minimum buy and q set prime But this one can actually be q prime q prime q prime I think this one is Slightly better Okay, now it's 10 seconds. That's a lot better than the 45 seconds before Okay, nice, and Is there like a date and set? Yes Okay, so this is gonna be I said from list And then this is gonna be I said no And then this is I said delete I said member I said member and this is supposed to be I said key a Couldn't expect t0. I said key. Maybe is it it's foldable, no? Oh, it's not foldable. They should be fine. It's a 20% faster, but yeah, it doesn't really matter at that point We could probably do the same here I map and changing this one to I map And this one too I map Isn't nice, right? We have uh, we have dykstra, right? And we just need it's very general dykstra And it does it in seven and a half seconds. Uh, it's all okay Okay, but let's check problem two So if your original map had some position with a risk level of eight Then that same position of each of the 25 total tiles would be as follows eight nine one two three nine one two three four one two three four five two three four five six nine three four five six seven Each single digit above corresponds to the example position with a value of eight on the top tile left tile Okay, let's just see what happens if I brute force this probably gonna be very slow, but let's see Task two So process a Okay, so we have the map okay, so but it's a risk level so Each time the tile repeats to the right or downward all of the risk levels are one higher than tile immediately up Or left of it. Okay, right So it's what mod modulus 10 plus one Okay, let's just see Okay, so so we have the nums Okay, now let's create the The ones that are like this Okay, so it's a five times five grid so, uh, let's just define the The grid a let's see five times five so It's gonna be plus one two three four and plus five Then it's gonna be One a one plus two One no, yeah, yeah No, it's gonna be two three four five six a three four five six seven eight nine and it's still eight nine 10 11 12 It's not very nice, but you know, okay, and then there's one more 13 14 15 16 17 okay, uh tile tile map Okay, then I do a so map. So this is just very Very annoying Okay, so first of all We're not gonna need the ones we might need the ones on the side Okay, uh, let's see. Let me check one thing. Oh, okay finally implants No worries. I think they Sorry about this. Well, okay. There's something happening with regards to the feedback. That's something So what is 20? So what is uh, okay? So if we just do it this way it's gonna take 25 times nine seconds That's a lot, right? That's like four minutes Uh, but let's see if that's okay. Uh, so we're gonna have a We're not gonna do it to tile map this way. Let's uh do it like this um So prok prok Shouldn't be right It's just hard to just just pre-process it Make sure here. Sorry. I'm replying to things All right Everybody's uh, there's a lot happening. I don't get it. Okay. Uh, oh, sorry This is my thesis Uh, no worries. It's gonna be published soon Okay, so how do I uh, how do I take So we generate prok So pre pre prok It's gonna be a list of lists Uh, I map so I map the prok and then So I'm gonna say map f x plus y so map map f x plus y over nums and x is a Coming from zero to five y is coming from zero to five and this one it's not happy with this one It's probably because I Didn't close this one now Pre-proked We're gonna say this is not gonna be like this is gonna be conkat All of these and we're gonna Conkat map I think like this and then this should be a list of okay, um let's see where f of a add a plus n is equal to So every time we add eight to the number it loops around so I think it's just a a a plus so If a less than n then no if a If n less than a a less than nine Less than or equal to nine then if a plus n is less than or equal to nine then a plus n else Um a plus n mod eight The mod nine plus one Let's just start with doing the pre-proked Okay, so now we have a list of lists A quadruple list of lists now. Let's not do it that way Sorry, uh what I want to do Is I want to uh take Row from a nums Okay, and then I want to concat map F a Where a a is to the r where a is taken from 0 to 5 r here is list of ints. Okay r here. Um, so f concat map Let's just run this on the example. This is actually going to be pre-proked task two over read input example map m print A pre-proked losing it So five two eight six six. Oh my god So one one six five three b b b. Oh my god Like this. Okay one one six five two Seven four two okay seven four two and it goes two two seven four eight six two five three three Eight five nine seven. Okay. I think that was one block three nine six four four four nine six one Oh, I think I just uh did too many Yeah, I think it's uh supposed to be zero to four Yeah, so then it ends with uh five three eight six Oh, it's supposed to end with four four four nine six Four nine six five three eight six seven three nine Okay, the looping is wrong It's one higher than it should be Okay, uh five five five one seven two five five five one seven two nine five two eight six four one seven one eight four four four okay, so this one is correct So pre-proc nums is this So I do pre-proc nums and then I do pre-proc transpose of nums And then I transpose that again so four seven nine four seven nine four one nine Okay, now we just have this extremely big one okay pre-proc Supposed to be nums here, I don't care about the path at all actually I am just going to see what happens when I run this Let's see how long it takes for the example 181 We're supposed to be 315 What is the path v putster lnp Oh, it takes a lot longer to compute the path this string I get this more fusion or something Oh, no, these were the input Let me just see what oh it works Oh, no, let's uh Let's see Oh, right I was trying to find the wrong path Okay 315 nice Don't care about this one. Okay. It doesn't actually matter too much. Um But what if I just don't Evaluate it even okay, so computing the path isn't really matters so much Okay But I'm not gonna print it Let's see This will should be pretty slow but I mean we are doing dykstra It's uh It's not a super inefficient algorithm. I mean so the The way we construct these things That's probably so I mean so the thing is like we could probably You know use There's some self similarity, right But the the problem is I think we um I think all the weights change I'm not sure that's um That's actually not have this c set member Let's have this be um If c set member oh, sorry C set If c set member path Then this I think it'll be kind of cool if we did something like Else There's gonna be c at fma y and we did something like Num This is into digit I need to import it. Okay, this should work. Um So this is well in task two input Of course, these are I mean we're repeating the code here, but whatever Answer some questions while I run When did we start it? All right, I can't send the f5 here. We just have to find the thread with all the cpu Want to um Share this is the ght up school language server And have some extensions and we have eight up and then d15 Oh, it's been running for Five minutes so far Uh, so it doesn't grow linearly That's for sure But uh What is the time complexity of dyke's thread? So like what what can we So it would be okay if like Because all of them Change right but not all of them equal like if all their weights were just added we could just pre-compute it Hey, but because it's only kind of one at a time Then it ended up being Uh Well, the path is kind of similar, right? It's been running for six minutes now and it took 10 seconds for the But if we increase the 25 fold three You will get there eventually I think we need to like we need to memoize it something At some point, right? What is it we can memoize here? We could try to like keep constant track of things, right? I give it like 10 15 more minutes But then I'm gonna stop for the day. I need to pack. I'm still waiting for feedback. So Yeah, I'm not sure what we can So I mean so we should memoize it somehow, right? It's definitely some repeated computation happening Because the map change, right, but it doesn't change That much Right Now it's been running so long. I'm kind of scared of shutting it off It's uh Let's just work in this terminal here Okay, we can't I don't think we can We can't do it for dyke's try itself Could I like, you know find it in one graph? And then just say, okay Find the shortest path from Yeah, because I don't know And to me it's also warning us, right that The memoization can't go wrong. It's been running for 12 minutes It's not consuming a lot of memory though. That's something Can I like use like a star like as a heuristic? If I because I know the solution to like one of them I can Uh, but I'm not sure it's guaranteed to work So three four two two One, yeah This is fun content, right? We're just staring at the code thinking of what to do Ah I don't know What we're doing Does anyone have any like ideas? Like how would how do you how would you memoize this? We want that star. I mean we don't want to run it all night, right? Let's at least copy this Okay, let's think. Um, I think one of the issues is that we just have a lot of nodes So can we like a Because we want to get to the bottom left. Can we like compute? From the left to Can we like compute from the left to? Because we know okay, we'll put that's the thing wait, we don't know that this is the shortest path So we could try like computing the shortest path for the top graph to each of the tops of all the nodes Like in one line, maybe I need like something like a floyd's Algorithm right where like compute the minimum distance between Because like the trick is right like if I'm in this route If I'm so let's see I'm This is like yeah, so so Computing all the distances between all the points In this map The shortest point shortest path between all points They would be equivalent in all these maps and then all these maps And all these maps all these maps and all these and all on this Let's see Let's keep this running Let's just see Indices Okay, so Pairs equal a concat indices Okay Indices and how do I compute all pairs? I do a A comma b where a comma a is taken from Concat indices and b is taken from Concat Indices This is all the pairs shortest path between Okay Okay, this one is not gonna finish Let's break it up Okay task to v2 Let's run that test to v2 on the example now We ran the dykstra And so let's call it run dykstra I don't really know how to correct it, learn dykstra A star And it equals Let's call this map Is equals to this This is going to be graph from edges mp And start to end vp is run dykstra Okay, so then we don't need this We don't need this So num It's going to be nums add fn Run dykstra equals mp Is run dykstra mp What did we call it? end map map end map map And then it was Yeah, this was start and end Okay, so let's Let's just compute it this way. We can't get the pairs And this is pairs of ints and then it's run dykstra a end map map a a b So how long does it take us to generate the list of these pairs So then we're just gonna say M map m We're gonna do a a So this is gonna be a comma b that's the pair comma a We don't care about the value and the p I'm gonna take this I'm gonna say print a comma b so let's just see call this m pair print pair putster lmp over task 2v2 pair pass It doesn't like it Why not actual type int come int Maybe int Maybe list of word x Yes, okay, and it's because I don't do path to string. So I will say full p2s is equal to path to stir over fmap So this is gonna be like this p Indices full p2s a concat map preprock pairs and this is gonna be full p2s over run dyke strap Now this is a mist. Yeah, okay pair pass could match type factory type a1 a Oh, yeah, so it's p That's a pair and then What does it say? Oh, okay So it's a so it's a comma b comma like this. Okay. Yeah, let me just print a comma b Let's just see how long this takes for All the companies are points. I mean printing takes a long time But now we see that So this is a point path from This point to this point. Let's just print to v here a comma b come out here To see how long it takes to print on the a case v of just n to n And so let's like without the printing. Let's just print the sum of all of the pairs Okay, it takes us three seconds to find all of the pair paths Okay But I don't really need the pair paths. I just need the edge pairs Right, so I am going to say here and Just path DDD task we do so what we're so this is conkat indices conkat indices So the indices are the index Yeah, okay, but let's see Path pairs is going to be x comma y where a x is taken from so Path pairs equals a path so edge indices equals and filter Is edge indices? Where is edge x comma y? Is equal to x equal to zero or x equal to nine Uh, no, sorry. Would these need to be general? And x equal to zero or x equal to FST end Or y equal to zero or y equal to s and d and Filter is edge a dollar conkat Indices Now I don't because I don't I don't just need to go from edge to edge Okay, so now we do the pairs, but we do Edge Indices, but yeah, it's just because I need to do like this Okay, so now let's compute for the edge Indices, okay that takes us half a second only Now let's say Let's just print that again. That was nice map m A v then we did something like print a comma b A putster lmp Okay, so all right, so this is Uh, but I don't oh this is like from the Okay, yeah, yeah, yeah Okay, so we filter the edge indices. So that is it's edge x y and Now say diff edge pairs Equal so this is gonna be a comma b a comma b Where a is taking from edge indices b Is taking from edge indices So this is like a a at x1 y1 and d at x to y2 And we want to make sure that x1 is not equal to x2 and and y1 is not equal to y2 And then we just take a comma b from diff edge pairs Okay, this is how the shortest path From edge to edge right So this is from 9 9 to 0 5 and Now this is also twice as many as we why did we We lot would Take us longer now And diff edge pairs And then we want to say We want to remove dupes And yeah, so we want to remove the duplicates right because 9 9 9 9 9 to 0 comma 8 is going to be the same as 0 comma 8 to 9 9 because it's a double-edged a graph and move dupes equal And so we're going to say nub by So I think we do nub by And just do nub Okay, so uh cannon so sort pair a a comma b is equal to a come if a less than b then a comma b else b comma e become a So we do a map sort pair And then we do sort And we do nub Okay, so then we have 8 9 9 8 We should have We just open this out file 0 0 2 9 3 9 4 9 5 9 6 9 7 9 8 9 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 9 9 right Okay, so now this is the shortest path Between two edges And these are going to be the same for all of the f's right, but I might have like a So now we know the shortest path from edge To inch Okay, now we had the we had the preproc right which was um So let's let's change this. Okay, so that last not like a concat We just take in And we don't do the concat We don't do any of this thing which just do a map map f That'd be a that's gonna be this map f Actually, I'm gonna flip it and say a nums a and it's gonna be a No, and this is gonna be a still nums actually Okay, but preproc. Okay. Okay, so we're gonna generate all the preprocks by saying a map so preproc equals a map a map preproc nums to 0 to 9 And they will wrap after that right you should be all of them Okay, so let's actually do like a task v to v task to big nums equals Where are we gonna take the preproc function here? Where okay, we take the preproc function And we are gonna say map so preproc is equal to a preproc. Yeah map Yeah, let's see We're gonna map a preproc nums to 0 to 9 and this is gonna be a map task to v2 to preproc So then we have a list for all of the numbers So for all of the pairs and all of them, let's just say That that's good. That scales linearly. So that should be nine times four Hey, let's do task v2 What does this do task v2 three? a print and then let's just This is a list of list of pairs so print dollar some dollar map Yeah, it's the same This is this pair pass of task three two three, uh, why is it now we have to What do you do like this? Okay, this is gonna be a list of lists of pairs. Okay, so we actually yes map i i comma preproc nums i Not like this. No, let's not do that We can just zip it again. Okay. We need to like this We want to get the a b the task to v three And we do print dollar some dollar map Okay, so pair paths here task to v2 big it's cool pair paths here is a list of lists Okay, so we say a Concat pair paths and then map this one We don't care about a we don't care about b we care about v Don't care about the path And I am actually going to make this a bit easier. I'm just gonna say int here and that's gonna be fine a When we do that by saying That this one should be in by This one is it may be in the run dyke strad And run dyke strad takes in this I returns the maybe path and maybe vertex Maybe Okay, so um I'm just gonna map a a comma b just v p to a comma b comma v comma v comma b Actually it just accepts that No 178 Yes And there's no complaints at all Okay, do I just sum up the cost of All the paths between all the edges just to see how long it takes 2.5 seconds Okay, um Let me check on my feedback Okay, um 164 337 Okay, now now we do the memoization, right? And we have to see here. Okay like We always have to go through one of these And we also have to go one through one like we can't We can't like skip I guess like from corner to corner. No, we can't go diagonally We always have to go through each of these sectors Okay, so that Okay, so the shortest path from here To here, right? It's the same as So we compute the shortest path from from zero zero to all the edges Okay And then we we look up the shortest path from any of those edges to any of the other edges And I like it here and then We have all of these edges But they will all be the Okay, we'll look slightly different Let me see Now I'm a bit stuck, right? Okay, so we go from zero zero to any of the edges Okay, um Okay, then we can kind of forget Yeah, okay, let's see. So let's kind of try and consume this Edge list here. So we have Edge so we have nums edge to edge Nums equal so okay, where e to e To e equals a task to big Nums Okay, so for the uh, so for the first one F We have a So we do like this we do a Okay, so we'd like this e to e. Okay, so we do Edge to edge Um, so the current offset is a zero And that doesn't actually matter Um, okay, because we don't have to return the path. I think So we have that we have the current zero comma zero comma zero And then we have the e to e Okay, so let's look at it Edge to edge Prime Okay edge to edge Okay, if we're looking at the We have the Kerr a costs Okay, and we were looking at the last one LPS Um Then we want to We want to find those And so in this case we want to find those that so is where a Go to So that go to And the edge And go to so this and go to And That's filter. Uh This LPS here Is going to be under the defined the the LPS here This is edge to edge prime All right, the LPS here are like at e to e Why doesn't he want to do this edge to edge is not like this so Edge to edge takes in A list of uh comma int comma int to And it takes in a list of your edge to edge prime Okay, and it takes in a list of the e to ease Which is going to be a this List of list of ease I'll just say it returns the int then the LPS here is going to be a list of int to int Okay, so we're gonna say G to g To e We're gonna filter we're gonna filter on a comma b And then we don't care about the path we found Where and Where a equals End or b equals end Of the LPS Okay So this is a g to e. So these are the ones that go to the end Okay, and now I have the current cost of arriving at the edges Okay, so I have to say a Okay, so I have to say here. Okay, so I go to the edges This is a current costs. So let this be not as it should be a A map of int to int Single term Is like this Okay, so we filter we find the ones that go to the Edge I just say These are the ones that go to the edge Um So either of these is equal to the end. So let's see Let's just do like this instead map maybe If a equals end Then a Just A comma and we just care about the value here We okay r then just a comma r else if b equals end Then just b comma r else nothing LPS So these are the The ones that goes to the end now let me actually We can we can do so if a is equal to the end so I can actually I can just look up the current cost. So the this is the other edge to a then a Let's actually do this Here where a eq e equals Map f yes So f equals So, uh, this one takes in takes in a comma b comma v p Okay now case a equals end And uh Just see is the Map dot bang. Let's see a We look up in curve costs. We look up a so then this is going to be An int so the total cost of getting to the end from that one is going to be Just a say which one we picked and we say A Yeah, we don't have we don't carry around it. So we just say v plus c Don't care about the path here Okay Same if p equals the end except then we look up Curve costs Map bang b equals just b v plus c Otherwise equals nothing Okay, and then we say a map maybe of these and so now these Are going to be this And then we find the smallest cost here. So the resort by a compare On snd We import this one a g2e And then this is going to be Min To whatever Because we know we know even we can get to all the edges, right? So it's going to be fine. This is going to be min And then we don't actually care about The coordinate we just care about the value Okay, so if we're at the end We do this Maybe this should just be All right, so which one was it? So this is just an so this is just From a to me plus c Okay, let's just actually Okay, we're going to do it the other way around. So this is going to be Okay, we're going to say this is this is going to be and we're going to sort we're just going to say map maybe here Okay, so if we're if we're at the end We we we can figure out how to so the cost of getting from all the edges to the end It's going to be exponential. That's fine edge to edge prime Curr costs Okay, and we're not at the end but we're at the So then we have lp lps Maybe this should be uh, not uh, this could be a map like this a map of in Okay, so uh, we get the Okay, now let's actually So here we're not gonna actually don't care about the current costs. I think just say Okay, so here I say costs Because I'll recursively call it edge to edge prime lps So then I know the costs for getting Uh from From all of the starts to all of the edges Okay, um I think we only just we just care about left edges. We're always going from left edges to the right edges I don't think this is gonna work out. You're kind of missing like how to tie the knot, right? Yeah, but I think we should still a let's drop the paths right away Here, I think we should do yeah, we should drop the paths Let's drop them here Okay, we're gonna need them for debugging. So let's keep them wrong Okay, what I mean like we're always going from from a left edge to a right edge So then we when we sort let's do that in sort there's sort There's So this is gonna be a if x1 y1 x2 Still comma y2 Let's see if x1 equals zero then x a add b add okay if x1 equals zero Then if x1 equals zero or y1 equals zero then a then a comma b and we know they are these are edge pairs. So um Otherwise it's gonna be b comma a Okay, so I guess I think I have to Like I know the value of the h I have to also know the value of the edges actually The from int to int So it isn't enough to do these into int For task 2v2 it actually has to I think we actually also need to know the value of that node Let's remove it here Okay, so I have this I want okay And I want to kind of stitch For these And they're always the same so it doesn't matter if I go Left and down Or down and right Oh, yeah, they're like mirrored also. I think um, but I'm not no but might might matter actually Okay, let's uh write that then um How do I stitch two of these together? That's also that's the thing right? That's why I need the I need the value of this node as well. Let's say type chord it goes int comma int just to make it a bit chord What is it complaining about now? This is fine. Okay. I'm not gonna I'm not gonna have a but there's already parts that are here. Okay That explains When does this Okay, so I'm not gonna I'm not gonna I'm only gonna take the edge end is this but I'm not gonna take the diff edge pairs What different edge pairs? Yeah, but I'm not gonna take only the Yeah, okay. I want the different edge pair So stitch nodes Um, and then whatever this is nums and then this is um, let me see, uh, okay, so I have the numbers Actually, I have a different pair of nums Uh, I'm just gonna how do we stitch these together? I still have feedback or maybe maybe I came in email I am going to Coit for today and you're just gonna run this You just say give them it um I'm gonna push it. I'm gonna run it. I'm just gonna let it run because it's uh I'm not I'm not figuring out You know how to do the memos. I think the trick is like you compute the edges to edges And then instead of having to put fine between every single point you always just kind of jump Um But uh, it's not it's not coming to me how to Finalize it right so what I'm thinking is okay, let's look Okay, so if I if I have zero and I know how to get to all the right edges Okay, then going from those to the new areas I can I can figure that out right by just adding one point everywhere Okay, and then I'm in the new area But I'm thinking like that's still That's still a lot of points All right, I'm not I don't know if that's any better I get from that to the new area. Okay, and then I can get from though and and then I Maybe I if I just do it recursively, right? So let me see now. I think I got it now So I I can find the Pre-processed ones Okay Um And then so so if I go from so if I look at the first Zero two so I filter out the ones that start at zero to zero That's also the the stupid thing like I don't Okay, so let's just do here a left edge Okay, I think I think I've normalized how the We did that right But always like the the smaller number is always on the left, right? The zero zero is always on the left And then zero one zero two Okay, so let me let me check Okay, so I have the task too big and I have these stitches Okay, um and then I edge to edge Close map task too big Sorry, I'm gonna see this undefined This is the edge to edge so a map task too big Map the pre-proc to Okay, so, um, and just A P P A P A E to E Now E to E Equals this Okay, so we have the lists here. Okay, then I do um So this is they're gonna be the Zero and then the rest just to have the types there a to e is zero and then the rest Okay Zero two edges is gonna be That was this map f function from before we were doing in edge to edge from edge to From edge on the edge And then a piece And then e to e to this e to ease because that e to Ease and then from each. Okay, this is equal to um Let's see. Well, this is if this is uh Yeah, so this is gonna be as said so it's gonna be listed. Okay, so this is gonna be an a comma b comma Okay, uh From edge of this if it's if you don't have any edge we do like this from edge map maybe f This is gonna be maybe f Where f a comma b comma b Equals a equals h case equals h Just b comma v b equals h equals just a comma v otherwise Nothing. Okay, so here we can get the From edge edges Okay Let me do f r zero equals a from edge zero comma zero And so this is like this pairs preprog. Yeah, okay So we do preprock preprock to map task to prepract Let's do sip preprock dollar map Ask me to There's gonna be a pair of int So this is gonna be um set to r So okay from edge We're gonna say here um a dks So we're gonna say a ns All right. No, this is gonna be a nums edges map maybe ggs Okay, uh Right, so this is the So this is so from edge to another edge. Okay, so from edge zero to zero comma zero uh on said This is gonna be um Okay, then we have a list of what it costs to get from zero to the other edges now let's just Just Scratch this into FR zero here Okay, so this is the cost of getting from zero to Any of the other edges Okay, and you can get from uh one nine to one zero Right That's how you get That's how you get over it. So we know how to get from zero That's a map into int Okay, I have our zero to next Each So this is gonna be and zero comma said and this is just gonna be We're not gonna hear about that here actually. Okay from zero to next edge We have this map of ints to int So we do a Google Map with key Map a function over all values Of the map So now I want to like do an update something like that Okay, that doesn't happen in a map. This is gonna be for zero to next Age now from zero to next edge is map dot to from this So we map. Okay, so Let's just write the so Two other edge A comma b equals okay If a equals nine Then it's a a And then it's a zero comma b And the value of it is actually a We also give the Nums here and the value is a nums Of zero of b Else it's the other one It so else it the a Is okay, but this one is zero and it's a gonna be a Zero Okay, two other edge nums So, um FR zero to next edge Um, so we have the these A a close map F2 fr zero Where f2 for H to Next edge We do nums and we do Itk So far And that's map f2 x so far Where f2 Defined so this is for edge to next edge. This is just gonna be a For now we're gonna say n zero And fr zero map dot from At least Okay map f2. Uh, so this is gonna take in the nums. Okay, so we say uh f2 takes in a a The edge A e and the value of getting there so for equals a A Where oe v equals a oe comma v plus oe v equals two other edge nums E Okay, so now we've gone And we've jumped one step to get to zero one, right? We have to go we go to All right, and so nine nine has two Ways it can go to our edges actually What does it? Yeah, it can go If a equals nine So this one has to be nb equals nine Then we have to go to the both edges Where e1 e2 equals the a comma zero Comma nums a p Then so then it's gonna be one comma e2 Else if a equals nine and e1 else To this has to be Okay from edge to next edge These are actually these are the only ways to get to to this Uh, okay, so case a equals nine Okay, okay e e2 Okay, so so I get the so the f2 the year I have the edge And I have the uh, so this is gonna be This is actually gonna be map a v plus f mapped over To other edge nums e Or from edge to next edge Yes, okay now Okay, uh slightly longer, but okay So we originally had I think this one is To get to nine nine we go get 40 now if we take one more step We can't go to zero zero again, right because we can't go diagonally Uh, but we can go From 40 To a zero So nine nine can go to Nine comma zero or zero comma nine. Yeah, so that's 41. Yes and then It can go to zero comma nine, which is 42 We should match the Yeah, yeah, that's two, right? Okay, so now we've computed how to get from here To any of To kind of these edges From edge to next edge Can't get map. Okay, so I'm just gonna take a list of list of nums and the list of list of Entbies And now okay, so we haven't actually gotten this far. So now we've gotten from here for all of these From zero to all of these Okay, and then now from all of these to one more step Into the next Quadrant But it's just not so practical for We took one step. Wow. We've been here for four hours. This is going on way too long Let me see. So what can I do with this? So I know how to get from these edges to The next edges, right? Okay, so what have I find now the Kind of the the shortest path From each of these For each of the other edges Where did I use this fr zero? Okay, this is From edge to next edge fr zero And then I jumped one edge Okay And so if I map this Now if I map let's have it from edge the other way around Okay, and so now I have this Okay, so now let me take These edges Where are these? Yeah, these are a list of instance b So a loop Okay, we are going to take a number and a In the grid, okay With the rest and then we're going to take the curves Curve shortest Now, uh, we're going to do the same thing here. Okay, so we're going to say It's going to be flip from edge G So that's going to be a function from undefined so Where f fe equals flip from edge G Now this f fe takes a list And uh Right, okay, so it takes in the list Through the loop here It's going to be It's going to be this monstrosity. Okay, but we don't care about that um Okay, so we take this and we for the curve shortest. What are the curves shortest that is the result Of this so that's a list of ints to int so a map So we have the cs cs cs v To a csv Okay, so actually you're just going to go to a map csv plus dollar f fe cs uh No over fe of cs Over the curve shortest So now this returns A list of list of the shortest um Take paths equals So this is the the idea here is okay. I flip the from edge Okay, I uh, so I have the the current shortest And the value of getting there I flip it. I I find the I do the from edges And the from edges gives me the value of going from one edge to the next one in in this Yeah, and it's like list of paths. Okay a giving me a This so these paths this is like the list of uh for each shortest Uh kind of the the cost of getting to the next edges Okay So I think that we can do here cs You can have this be cs comma This no want to cs here Because this compiles Okay, so now this is a list for each of the shortest Uh What it costs getting from that path To all the next ones and the total cost of getting there And so it's gonna be Okay, so I think I have to So I don't take the cs here but I um Okay, so this will be the the cost of getting okay, so and then I do a So this is actually a concat map Okay, so this is gonna be a A list of ab's again a lot of these a's will be the same So I want to do So for each of the new edges, I want to find the shortest path there. So I should be able to do a sort by Compare on first so we group by compare on first a group by Equality on the first Okay, and then I do map Minimum by compare on S&D Um by and then this will be the list of the minimums of of getting to the next one Okay, and then I have a the paths taken And then we want the Yeah, and then we just do the FR so I think it's just a FR To next is gonna be FR edge to Next edge of the numbers And the take paths the types here match up Um and can this be I just loop R to next Okay, but I want A if I don't have anything left to do actually, um Yeah, if I if I'm on the last one I want to do something different N9 N9 comma g9 because then I don't want to take the next step per shortest I still want to Take all the paths By doing the ffe Where I still want to take all the paths undefined And then this is going to be g9 and this is going to be Yes, but a take paths I just want to do a map dot from list A or a List dot look up I think I can just do Look up and it's going to be a length going to be N9 at N9 one Okay, N9 one It's going to be a length of N9 one minus one comma length of N9 So this is going to be my god Is it going to be a not look but look up? a take paths A And I think What's the type of look up? Yeah, okay, and it should be there from just So this does not start at one zero, but it starts at This one actually starts a Let's go loop R and we start At a we started this one actually loop a R It's running for the example 148 It's calling from just and it doesn't work. Oh look up and take paths. Okay. Let me just see what the Take paths here return actually I mean I found something Just 244. That's not the threat. Oh, it's 350 Can I just do here a loop e to es And say zero comma zero comma zero that's actually yeah That's something but then um, okay. This one doesn't work though, but let's just see how fast it is on the input If we're like If this is super slow anyway, there's no reason to try and improve it, right? Okay, so this one is also slow So it doesn't even matter Oh, it's still super slow. It's not doing anything So we're gonna Yeah, let's cancel this one Eh making sure I'm not referring to anything wrong Yeah, I mean, this is also like it doesn't actually do it, right? So It gets the example wrong and it doesn't do it. So it's just uh Anyway, it was worth a try right like figuring out the shortest path blah blah blah and then I was taking them jumping But actually it finds this shortest path from zero to the points on the other maps But I think it gets screwed up Yeah, it's because it's returning a shorter path And it's probably because it's not okay to just jump But we still should still should have fewer edges Doesn't work we don't consider that Going down then Right is not the same as right right and then Okay, but I go to the next one. That's I think that's fine But I think it could do something right? I think this could be a solution You kind of do it like that You don't compute again again All right, but it doesn't work. So let's just Call it a day for now. I need to do stuff Let's just run the task two on this I'm just gonna run the Big one and uh, all right. Thanks for tuning in. It was a four and a half hours Nothing happening mostly Eh, which is not that great, but thanks for tuning in anyway. All right. Bye. Bye