 All right, welcome to today's habit of code. Well, yesterday's habit of code. We're doing day 17 today. We did day 16 yesterday. We're still catching up, but we had a sneak peek at this yesterday and we did the parsing. But we figured out that we would need to do some path-finding algorithm stuff and 40 minutes didn't seem enough to get it done. So I decided just to do it now in one day. And let's see how it goes. All right, so we coded up the parsing. So we are taking this example text here, parsing it into an array. And you can do arrays in Haskell. They can even be mutable. They can have, you can do matrices. It's not too bad actually, but obviously they're a bit more difficult to work with because you don't have like built-in syntax for arrays as you do with lists, but it can all be done where there's a wheel, there's a way. So let's remind ourselves what we are doing. So we're kind of, we released the lava and now it's flowing down and we want it to flow faster. So we put it in something called a crucible, which is this kind of thing. It's just a big pot basically. And we're taking that down and we want to find the one that involves the least heat loss and so we get this. And then what we want to do is we want to get from this top corner here to this bottom corner here, but we want to do it in a way that minimizes the heat loss and the way we're going to do it is that we're going to look at the numbers here and pick the shortest path according to these numbers, which is just a Dijkstra's algorithm. Aijkstra's algorithm and we're probably going to do something like A star actually, which is Dijkstra, but with some extra heuristics, which makes it a bit faster. So Dijkstra, so what is Dijkstra? So how do you do Dijkstra? What you do is that you have a graph like this and then you have some neighbors. And so you basically, yeah, exactly. So you mark all nodes as unvisited and then you have all the unvisited nodes and then you have a tentative distance, set to zero for initial node and to infinity for all other nodes. Now during the run of the algorithm, the tentative distance, then you just get the shortest path. So it's basically breadth first search, but with distances instead of just always picking some neighbor. Okay, and through the current node, compare and you'll get the one currently assigned to the neighbor and assign it compared. Okay, so assign to every node a tentative distance and set it to zero for our initial node into infinity for all other nodes. During run of the algorithm, the tentative distance of a node, the length of the shortest path discovered so far. There's initially no path that's known to any other vertex. There's gonna be infinity and then we just find the shortest distance. Okay, so let's say now my mouse start working again. Let me plug it in and plug it, plug it out, plug it in again. All right, mouse which is stopped working and then it started working, but then it stopped working again. Now I'm back to this one, which works again, but it keeps stopping and keeps dropping up, but I think I get a new mouse for Christmas, so don't worry about that. So let's keep this to the side and don't worry about the copyright on this picture because I took it actually. D, D, D, D, D. Let me say we are going to, I wanna put it like this and then we want this one over here and then we make this example a bit smaller because it doesn't really matter. Okay, so we're gonna take in the array of int comma int, int. And we are going to make a copy of it, I think, for the distances, data.array. Okay, and can I map over the array? It's foldable, it's a functor. Okay, accessing arrays in the delimbs. Ah, of course, I can't easily update the array. Let's see, we'll go marray. So we have mutable arrays as well. So let's do this. So Dijkstra is gonna be, we take it in the initial array and we are gonna take in the initial node and we're gonna take in the target node. So now we're just gonna do a Dijkstra, simple Dijkstra, and then afterwards we're gonna do this because we can only move three in a row at the start. So we're just gonna do that a bit later. So this is gonna be monad, marray, starray. Something like that, marray, we can actually just make it an IO thing, IOint. So we're gonna have a bunch of side effects. Let's make it st of int, I like that better. So I wanna see, so starray is gonna be an st. It's gonna be an st. So I kind of forgot how to do these. Let me see, int. So now we're gonna do dijkstra is equal to do. So we're gonna say run st, do. Now this run st comes from the stmonad which is in import control.monad.st. We have some mutable arrays also import data.marray.marray. Data.marray.marray.marray. And we're gonna say import data.marray.marray.marray.marray. Let's see, qualified. How's everyone doing today? Run st, and we are, we want the monad array. So we wanna say here do x is ma.newarray. And we want, we're gonna have it the same dimensions. Let's see, r init target, run st, do. So r.bounds r. So converse, so thaw, yes. I think I can just actually convert a mutable array into a mutable array. So I can just do x is ma.thaw, r. And I think it's gonna complain now that it's not return zero. It doesn't, we won't know what value of the b. So because it's saying, so it's not supposed to be ints. But it doesn't know the s, so I think I want the add starray. And then I need the language you see, 2021. Does this one work? Oh, maybe I have to do ma.starray, do, ding, ding. And it doesn't want that either. So what is this data.array.st? Import data.array.st. What is this save? Eh, Google, data.array.st.save, the save API of only, oh, okay. I think it's gonna be fine. But let's see, now it's complaining. I think starray has kind, starray.starray, okay, yes. starray, the state variable argument for the st type. Let me see, can I just do run starray here? Cannot, okay. And then ma.freezex. Ah, because it's saying this, okay, array int comma int, int. Okay, so now this one is an starray as, and then it allows me to just return it. Cool. What do I get if I do read file, read file example, print dot parse dot lines. So here, this returns an array int int. So if I do, okay, I wanna do this, actually just need to hear it. Cause I know I'm gonna go from the top left to the bottom left, where init is equal to init comma target is equal to r dot bounds r. And now let's print the parse into the extra, oh, it just works. Okay, cool. Then I can probably do, so I can saw the array, and then I can also do, let's see, I don't need to saw the array, I can just do dists is ma.newArray, and I want it to be bounds and I want everything to be, so the enum type class. So I want it to be just max int, right? Enum is the bounded class. Let's see, enum max bound is called bounds max bound, max bound at int. And now it doesn't know what to do. So I'm seeing new array, let's see, what is the type of x here? sd array, s edge, sd array, sd, oh, okay, so it's a big a here, and it doesn't like this because, let me see if I can bind the s inside here. Let's see, this is gonna be sd array, s int comma int, right? md, md, md, md, md, md, md, md, md, md, md, md, oh, no, sd array, int, int, int, right? So this is gonna be the s and int. I think, let me see, that's kind, what do you want? Okay, what do you want here? New array, okay, a0, so okay, add int comma int. Is that sd array? Yes, nice. So now, because I bound the s there, so now this is all max int. Cool, okay, let's go back to Dykestrap. Mark all nodes as, mark all nodes and visit it. Okay, now I also wanna modify, I wanna set the, read array, write array, exactly. So I just wanna say here, write array, dists, zero comma zero, zero. Then we just set the distance of this one to zero and then create a set of all the unvisited nodes or the unvisited set. Let me see, on the st monad, I have some state, right? And I can do stuff with that state. And I can have the st ref. And then let's just do here, scene is sd, new, import data.array.st, no, import data.st ref. Who says you can't do imperative programming? It's also the best imperative programming language, you know, that's cool. Let's see st ref and now we have data.set already. It's gonna be set.empty. And now it doesn't know what scene is to be, but mark all nodes, create the set of all the unvisited nodes called the unvisited set. Okay, assigned to every node a tentative distance, zero for initial and initial nodes. Okay, so for the current node, consider all of its unvisited neighbors and calculate their tentative distances through the current node. Okay, let me see, let nas is equal to map maybe, so we have here x to a point p is a point, map maybe f to left, right, up, down, where, let nas be where f, okay, so let's first write the f here, f is equal to move fp is equal to move, this is fp at your case, move p of, move p there of y comma x, then we check that in it at i x and target is equal to it, no, ty tx, okay, so just have to check that i is less than or equal to, is bigger than or equal to i, you just make it like this case, so it should be larger than or equal to iy and x should be larger than or equal to ix and then we should have y less than or equal to ty and x less than or equal to tx, and this should go to just y comma x, otherwise we go to nothing and now map maybe is not imported because we don't import data, maybe import, data, maybe map, maybe, okay, so now we have the neighbors, okay, so this is the initialization, initialization, do I need this x here, yes, do run st array, so let me just say that can I do something like this, just to get the, it doesn't like this, it doesn't like this, what is the type of this, return, okay, let's just grab the st here from the x, looks like it takes long, so let me initialize it and then what are we gonna do, how's the audio and everything by the way, I hope it is good, looks good on my end, but let's see, okay, now so we write the tests 00, let me say go is equal to, so we have this go, go empty is equal to tests of target, tests ma, why doesn't it like this, I think it's just being, do, what is it, so go, tests, do I have to do ma, go, next, so send it around, okay, the current draw to the wrong room, the tentative distance of a node v is the length of the shortest path, this car is so far between, consider all of its unvisited neighbors, and calculate their tentative distances through the correct node, so then we do here, where, let me see, nays of next, let n's equal nays of next, in map, r dot n2, that is, why can't I, how can I, couldn't match expected type, array int int, array, why, so what is the type of go, go takes a list of int comma int, and returns sts int, okay, so here we're gonna do this, r dot bang, target, okay, so how do I access m array, I have to do read array, right, sorry, so I'm gonna do this, m a dot read array, target, okay, that one works, okay, good, okay, m a dot read array, dists, these is equal to, I need to do this actually, these, so this is two, okay, ds, map, m, and then this one is, what's the type of this, so this is just a list of ints, and what is, can I do a zip with m, let me see, and then I want ns, ns, I just wanna do, I need that f map m, and I just wanna do n comma over, so then this is a list of neighbors and their distances from the current node to the current distances, right, okay, so tentative distance for current, consider all of its unvisited neighbors, okay, so I also have to do, so I also have to read as the ref, unvisited, unvisited ref, okay, so unvisited is like this, and then we have neighbors, and we will say filter, not dot set dot member, flip set dot member, unvisited, right, maybe not flip, ns, okay, and I just do it like this, so these are the unvisited neighbors, and then I read the distances to those, consider all of its unvisited neighbors and calculate their tentative distances through the current node, okay, so the tentative distances, so the distance of the current node is gonna be current dist, m8r read array, next, dists next, okay, and then the tentative distance, mm-hmm, mm-hmm, mm-hmm, so read array, dists next, and then I read all the, compare the newly calculated tentative distance of the one currently inside the neighbor, and assign it, if node A is marked by the distance of six, and the edge connecting with the neighbor is at length two, then distance of B will be A will be six plus two, okay, so then I wanna say, right, so that's okay, so the current dist is a, so this is the distance of the next, so ds tentative, ds kerr is gonna be, is gonna be, but then here we don't read the dists, we read the, we read the x, okay, and here we don't just do, and prime we actually do um, plus kerr dist, okay, now we have the, ds tentative, and we have the ds kerr, we can actually, we don't need to zip this, mm-hmm, mm-hmm, mm-hmm, let me do it like this, just removing some craft, mm-hmm, mm-hmm, mm-hmm, mm-hmm, and I think I need to do fmap dot, okay, ds kerr, there's a list of ints, and there's a list of ds tentative, and then, mm-hmm, mm-hmm, mm-hmm, mm-hmm, mm-hmm, mm-hmm, mm-hmm, oh, and we also want to write the parents, okay, let's see, and parent, we have the same bounds, but here the maxbound, let's just have this, nothing, the parent of every node is nothing, so I want to say here, map and on zip ds tentative, ds kerr, let's actually have the node here as well, okay, let f equal, so we're gonna say here, f, and this is gonna take in the neighbor, and the t-dist, and the kerr-dist, equals, so if the distance kerr-dist is less than t-dist, then we do write array parent, we write the parent array, and we write parent of n is going to be next, let's change this next to kerr, okay, kerr, kerr, kerr, mm-hmm, ah, man, then, this one changed, okay, write any parent in just kerr, okay, so, and then I write the array parent just kerr, and I write array dists kerr-dist, so that is like if it's the case, Ls, return, I don't know what anything goes, write array, return, yeah it shouldn't return anything, right, mm-hmm, Okay f is type takes in the income int, the neighbor and then the disk and then the current just to sts and it doesn't have the oops okay so then I map pscur and now I've also discovered the new neighbors so I want I'm gonna add those to the queue a visitor novel let me check again okay if that's in the market visited mm-hmm okay go a c k c is equal to target then I just read the distance to the target because I have found it okay otherwise we update the parent web to the tests and then we go go and now we just add the neighbors and s to in front of the rest I think this will work let's see mm-hmm but I never did go so I'm gonna say he this is go in it mm-hmm but I didn't I also have to I have to write s t ref and visited ref a set that insert cur and visited okay saying the distance to the target is 79 mm-hmm let's just consider this for a moment of course this is the path I want to so I want to actually say here I want to return a list of so pass that's your trip so path is gonna be reconstruct pass reconstruct as cur is equal to cur so we do read ray parent cur so case reader a parent curve of nothing the empty list at just p to cur reconstruct path and then we just occur over reconstruct pass p no reconstruct path read array is gonna be in comma int to sd s int we need to turn here and this one is supposed to be comma int reconstruct path so p case reader ray okay just p why is it maybe maybe apparent okay read array parent read array it should not be this okay so parent is a maybe int int okay now so we take in the m r a a e n why is it just just p that is very strange return reconstruct path no instance for m r a s theory maybe maybe yeah because it's not just just mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm-hmm mm- is the shortest path but it probably yeah so it takes a lot right a lot of times which is not good I think this is actually we want to have the actual path okay so how does it go we go 0 1 0 2 0 3 4 5 0 7 8 9 10 11 12 and then it just goes down okay that's funny hmm okay um anyway we have a pretty good dike's thread now with the distances and paths and stuff like that and then if it's within bounds um then we're okay otherwise let's see well this is the heat loss of 102 so what I think is a trick that we have to do here let's also just let's just let's see if this dike straw works on the input I don't have the input yet that's gonna be huge I already have input what okay save it I just want to see like if the trivial path okay so it takes us doesn't take us that long um so what I can also do is I can make this into and we can add a heuristic right by sort by import data dot list sort by and then um heuristic so then we add the heuristic here array it that basically makes us an a star uh let me see uh google sort on is probably better actually int int to int and then let's make this sort on on sort by sort on here we're gonna call it here print dike straw and then this is just gonna be the first first uh yeah first so actually it's better to have I think a b like int comma int to int comma int to ordering and then we actually do to sort by then let's have it take the heuristic pair first just to make it smoother okay and so dike straw is just saying they're all equal so then basically nothing should happen but it takes a lot longer but here actually if I then make this um x comma y and then let's see f comma a comma b let here equals f a b uh here uh a comma b c comma d is equal to so then we're just gonna take the we're gonna come compare them on the distance to the target mm-hmm that's like a star right so so uh and for us that's actually just gonna be um compare a times a plus b times b with c times c plus d times d uh but this is actually wrong so we want the opposite order because we want it to so that the bigger one is first okay it just doesn't it doesn't really help the sort by the heuristic here so then let's just go and we always so I think it's also because here we're also always putting the biggest one first okay uh so let's not bother with a star or anything like that now let's focus on making the path like making the path proper mm-hmm what if I and so you might not always have this on a grid right so this is the extra with arrays let me just okay maybe I can do it like this trace show m if I want to just see the path so the shortest path is 892 uh if I ignore this takes like three distance rule so let's see I think this dykstra works but it's this dykstra on a 2d grid right and extra let's rename it um so what we really want is we want to we want to make sure that so that I think we can kind of just do it so instead of giving it just like the ones that are one step away we want to give it the ones that are um two steps away and then three steps away and then just do this um it would be nice if this was just a dykstra because then we could also test our dykstra right I feel like also this would be like a nice nice part two but what do I know uh let's see okay so let's actually let's just convert it into a map okay so dyk dykstra let's do this all over again and call it dykstra map okay so now what I am going to do okay I have um because I don't know what need to know the so then okay so neighbors so map maybe fp left right up down so the f is just let's change that to be inbounds okay um let's see this is such a stupid name actually uh because we're not actually doing anything with this so let's write inbounds p there true false filter okay and then map move p then we just filter them first and then we do map move p okay so neighbors so this is uh the one step neighbors so let's let's make a list of the neighbors okay uh these are gonna be paths okay so we have nays so for every path we have we can take um we can take a left we can take a right we can take down we can take we can take uh left left we can take um left left I think I'm doing this in a weird way so the idea is to just okay maybe I can filter out the legal neighbors uh okay so I have 24 so I have these are the ones in bounds okay let's see goodness is Curtis um okay so first we will say okay do so I be let I be equals okay mm so then I want to see what is the path to the current one uh parent okay but this won't so we were seeing an array again it's not good but it's okay uh no this is the one path we can't go to the current one okay so let's just say um so just p is gonna be so let's do a read array p current mm okay and reader AP curve and cp and then um cpp is gonna be case cp of nothing then so if it's nothing we it's just um nothing um just p read array p uh parent p okay read array p read array parent and nays okay so nays okay this is curve let's see um so I want to see here um so cp is read array parent curve so if there is no parent k cp of nothing then the main neighbors are just move uh curve curve I be it's map move curve IP so if a cp is something if it we have a cp just uh curve p then I want to see how did we get there so from there's gonna be y comma x and then y1 x1 y2 x2 case a x is equal to x2 and so if it's the same um that's your y is equal to y1 so it's the same line a is equal to if x1 less than x2 so to get uh then so to get from uh y y y1 point 1 to point 2 you had to go right else left otherwise so then x1 is equal to x2 if y1 is less than y2 then to get from there you had to go then down else up okay so to get from uh curve parent then um so we want to do here actually case just car so if we have a parent then we want to get the parent of that one cpp to okay cpp I know I can just like do some map so maybe won't add stuff here but core parent parents yeah but I don't feel like it and I don't exactly remember how to do it but it would be very nice and let's just uh because I because I also need to do the reading of the array right let me just see what maybe I can just do it um press okay so do just read just curve parent read array parent curve okay and then just curve parent parent read array parent curve parent return maybe does it work like this oh okay I guess so um read array parent curve read array curve parent parent and now let's see if so let a d curve is equal to from so to get from y1 to y2 right uh so to get yeah from curve parent from uh curve parent to curve and d d parent curve and then d parent parent it goes from a curve parent parent curve parent and let's see then if and if d parent curve is equal to d parent parent then filter is equal to so not equal to d parent curve so I just remove the direction that would cause it to be the third time okay uh return and then this is just case res of let's just say here from maybe ib res and this I need to import from data dot maybe and then I want to do map move map move curve from maybe uh ib so res here oh okay yeah and there's no monad fail right because this isn't um because it's not in the map monad right and I had to lift you know something ah okay let's then just do it differently okay and mb curve parent do mb to curve parent case mb curve parent of nothing return ib okay um um just curve parent do mb curve parent reader rate parent case mb curve parent parent parent of nothing return ib just curve parent parent no do and then we're gonna go left we're gonna go left and then we're gonna say if then else okay now we don't need any monad fail instance now it's not finishing that's not good uh it's just not finding any route to the target I think or is it because I forgot to filter by the unvisited no and it's prime and it's prime ah yes okay but it's saying uh 1533 instead of instead of 102 so it's something wrong in the example at least okay so it goes and they don't they think it's doing something correct okay so it goes at zero one then it goes down one one okay and it goes we want to okay then it goes this is uh oh it goes zero one zero it goes zero one okay this is zero one then it goes um then it goes one one and it goes one two one two and then it goes two one or two two yeah it goes down again and then it goes two two three three four four four so it's not just not getting the right path it does get to the end though which is nice did I maybe flip the from let's see a let's actually make this a lot less indented so I filtered out those interactions so it went okay it went okay so it went let me now actually do um okay let's just look at it okay so it went zero one zero two okay and then one two okay and then I want two two um right let's see so zero one oops sorry zero one zero two one two two two two three three to four the three to four three four four four four five four six five six oh no five six six six seven six six seven six eight seven eight eight eight eight eight nine eight ten nine ten seven okay I got they got something wrong for sure let's see I maybe we maybe we can't do it this way so we're getting the shortest path to a no and then we're just making sure that if we have two parents maybe I should always update no we get the same oh we gotta get a different path though so this is neighbors curve let's call it valid neighbors okay left right up down and then yeah because they're not valid neighbors right because you we so now so we're looking at the neighbors and we're saying that if the way you got here is left and the way you got there was if you the way you got here is right and the way you got there is right then you should not take the right neighbor right we got this one wrong valid nays let me see okay this one is just doing nothing okay maybe current parent of nothing current parent so how did you get from current to curve so if the lines are the same um if the lines are the same so if so then get for x1 to x2 if it's right and it's right otherwise yeah okay so otherwise so let's just see x1 equals x2 so if you're in the same column then to get from y1 to y2 uh this one should be up if y1 is less than y2 then to get from y1 to y2 you go no it's down actually uh yeah it's down hmm let me just check uh assert that move deep parent curve uh move a current parent deep parent curve is equal to curve import control dot exception search and i want to i want to make sure that move current parent a deep parent parent is equal to curve parent valid nays is apparent to too few arguments map r is map move curve res return r oh this should be a list actually okay let's write it down valid nays int comma int sds in comma int valid nays non exhaustive patterns in function from didi didi didi otherwise equals error from and then show p1 p2 p1 p2 okay and why is it calling that didi didi didi so there's no way to get from zero one to one two right okay so it must have written at some point why is it writing that it can go so all of them are really generated by this ns function right so i'm gonna say let ns prime for valid nays current and we just do this ns thing mm-hmm ding ding ding ding what's the type of uh assert assert mm-hmm mm-hmm mm-hmm mm-hmm okay and do trace show m curve curve parent trace show m curve curve p okay and then so do curve and curve parent ah this should be curve parent okay then these were the right directions okay so it's not so the direction thing is correct it's just that it's not good enough i think mm-hmm so the from function is correct also and now if yeah so if you took the right you took the right i think i need to do one more layer maybe i just think it's the yeah i think it's one more layer okay let's do it again uh do mb let's call this one bppp is read read array parent curve parent parent do uh case mb cpp of nothing turn id just cpp cpp p is gonna be ppp p actually ppp p and do and then we're gonna do this whole thing let the parent the parent parent the pppp is equal to from curve from um cppp to curve parent parent if the parent cppp is equal to the the parent parent mm-hmm what's wrong with this whole thing i think it's just indentation right and the parent curve is equal to dppp so they're all the same then we can't go right anymore dppp we're still getting 117 so if it is and we have to turn 90 degrees we're not allowed to go back i think that might be the thing so let's see um then if dppp is equal to um member if dppp is equal to left or dppp is equal to right then filter in bounds or right up down else and then left right no i still get let me see okay it's not enough to just go and say like the list hey little any it's going okay i guess and we got the breadth per search implemented but we are still we got the dyke strain implemented but we're still working on we're still working on the the extra thing so see if i just return i'd be always so all the neighbors are always valid then i get 79 right if i try and filter so that let's see okay but it seems like i'm closer now so now it goes from it goes to zero one first right and then zero two and then it goes to zero three okay and then it goes a one three one four some indian candy super good it's called kaju katli it's like cashew flour and ghee and sugar it's quite good mm-hmm let me print this past on the mm-hmm they're super good sugar ghee cardamom and cashew flour so the end result it takes care of the filter something is wrong here also so here it goes one step two steps three steps to the right so it was doing the right thing before because now it's just taking two steps four steps in the right wrong wrong in the same direction so we have to remove this step the parent curve so let go two three four and then we change direction four five four six so here we don't have any three more than three in one direction okay so here we go you know we went we go okay so we go down down so down and then right right down down right right down down right right mm-hmm down down right if i make this a largest larger than i can yeah mm-hmm now a bit stuck actually again left right up down is to right uh down left up let's just make it in that order and then it gives it a different response which is like okay that's not good and it goes um goes right it goes right we go right right down down down oh wait sorry we go uh right right down right right i i do think it's actually the other one because we're allowed to have uh right right right mm-hmm uh mb cpp read array array and parent parent parent case mb cppp of nothing return ip there's the pppp of the pppp from cppp uh sorry cppp ppp and the curve parent parent parent parent the parent curve is equal to ppp mm-hmm then you have to turn okay we get 115 then it goes right right right okay it goes um right right right let's have this actually be let me just change the bounce here so that it is um from one one two so just that it matches the lines here because there's no reason to have zero in texture arrays okay so we go um one two a one three one four and then it goes down to two four and then to five no to four to five right to six to seven and it goes to one seven one eight mm-hmm one eight um we're going to one seven one eight one nine one ten two ten two eleven two twelve no this is oh shit we want to one ten so two ten okay then two eleven to twelve two thirteen three thirteen four thirteen five thirteen five twelve so we're we're having we're getting a similar kind of shape of path but not mm-hmm but we really shouldn't be getting a different parent okay yeah because it's it's not path for a search okay if we don't have a parent then we can go anywhere if we do have a parent then we need to check if that one has a parent if that one has a parent then it's current parent parent and then we'll rewrite current parent and none of them okay so then okay and if we're all the same direction then we have to turn and then we turn and if we were coming to the left or right then we have to take a 90 degree turn which means we have to go either up or down otherwise we're coming from up and down and we have to take a left or right let's make this down up and this right left and then it also changes the path again which is very annoying but that I that's what I don't understand why does it change the path I would obviously it selects a different path but it should be still they should still be equally short so if I got that's the shortest path to getting there right maybe I should return and here return just and otherwise return nothing and let's say this is incoming so I'll only return the ones that I found the shortest path to maybe so this is map maybe m no let's just map map m f m b n s n b n s prime and this is then cat maybe's n b n s prime import data maybe cat maybe's okay it doesn't change that one to just add the ones that we just saw maybe we're seeing nodes um twice that could also be it filter not dot flip that dot member an usage itch but we already know we already take care of that by whenever we look at the neighbors we filter there in the visited set and they're never gonna be there might maybe they're at it twice but they're never like looked at if they see them again I think we always need to explore all of them and this is in the distance to the target so do dt and then it is actually dt plus plus so it's we read the distance to the target and then we also want to read the current is the freight area okay so it is this so m a dot read array x plus we need the so because we need to get to the target and then we need to get okay and then we get out of the target but so um maybe not so we get that the target is in the path right okay and then this target go in it so then I'm just gonna say reverse reconstruct path and let's see what happens if I just add together all the ones in the path a map r r dot bang pass let a p links trace show m pass trace show m p links okay so we're getting the right path links as well that's like that's not the case so four one and then why does it choose the three and not the one that it chooses is three and five and then four three and five and then four but why doesn't it choose one and five and four that doesn't make sense so it sees the ah this is curtis aha I think so this should not be curtis I think this should be uh oh no okay it is uh so we read the array of x yeah okay this is the this is the length if we get there let me see what if I just reduce the example a bit let's see example me him okay oh this is not this is the wrong so here let me see I want to go um let's just do it like this and now let's print the example min here example and okay then it goes um it goes for one one three it goes for one three five and it should go for one one five can we even leave this it goes for one plus four one three three five and it should go for one one five okay and that's just uh let's just see here trace show m cur trace show m ns okay then it looks at so the current one is one one the neighbors are one two one one the neighbors are one two and two one and let's actually do trace but let's just do um um trace show m dists I can't do that because I can't show the dists um read array get a socks m a dot okay I think I have to do to do like this okay so okay so it's one one so we have two one and it's a one two two one and after I found it okay so then this one is zero that's true the distance to distance to one two is um four okay then distance to two one is three yes okay that's correct so then I go to one two and its neighbors are uh these neighbors are two two and two one three okay yes and then I get that the distance to two two is six that's two plus four plus yes and the distance to uh two uh two one two one is let me see two one is three yes two one is three still okay so the distance to two two should be six and the distance to one three is five so four plus one okay then one three so one four and two three then one four becomes eight which is five plus okay and two and two three is six okay so okay it was four one um okay so now it's it's correct right it's six okay so now it goes to it goes to one four and that it's only neighbor is two four and it finds out that the distance to four is 13 okay two four is 13 I think it's maybe just because I I finished the search too early then it goes for one one five okay I think maybe what does it say for the example now still says one two one maybe I need a probably need a priority queue maybe I can uh so when I do neighbors here I'm not gonna so this is gonna be list of income and and this is gonna be like this so I always want to select the right order I think okay and the rest cat maybe is mbns so this one is actually gonna be it's just gonna be it's not gonna be map maybe anything okay we're just gonna have income by int but we have also gonna have the new distances so then this we write the parade parent and then we write the new distance let me say card dist otherwise uh otherwise we return a n comma t dist and then we might see nodes multiple times but with a different parent so then we just say n as prime we add n as prime here so we go the init and it's gonna have distance zero and now we are gonna do sort on second we're gonna say sort on here we actually don't need to trace as much maybe the maybe it's if it's so then now we can throw out the visit if it's visited um let's sort on second filter not dot first not set out member visited dot a mm-hmm oh this is actually visited it's not and visited so then we visited it's really successful and we're getting there at the shortest path we don't want to go backwards okay let me just fix this so we don't want to have a visit but we also want to remove all the we want to remove also the curve right i think it might not be going twice in the curve filter and not equal first curve not equal to curve i think we need to actually print out the the lines because now it seems to be going three two one five three two one five and also to be going four one one five is how this left down right up okay so now at least it doesn't change the up down okay so now at least it doesn't keep changing depending on what i write so four one one five has a path length of 11 three two one five also has a path length of 11 so those two are fine so it goes um three three two one so we should be getting 102 here but we are getting one we are getting 113 you're knowing let me just make sure paste this again let's see add two one two two it would be very nice if i could actually let me see um so let's give me the path and um we'll print the path what i want to do is i want to do the parse again except this time i'm not gonna return the ray i'm just gonna return i'm just gonna return a list of list of int comma int comma int parse two and i think it's just a res now let's say p2 is read file sample return dot parse two dot lines now let's say here let p set equals set dot from list path and then we're gonna say map m map m putster ln dot f on p2 so let f equal so we're gonna say here this is f coordinate value equals k c member set dot member p set so let's just say if c is member p set then print x else we print uh show the uh this is gonna be completely messed up um because we don't want to put string ln put string and then we want to say ln look at this i think they should work okay so here we do get the path that we took three two one uh but then it goes okay it goes up and then it goes right four times let me see we're allowed to do that right so we go up and then we go right three times and go down and then we go right and we go one two three and the left down right one two three it seems to be a valid path at least but it's just not the shortest one so db file able to do this debug file file db example m ding ding and then we want to debug db okay what if i try and what if i just return ib here so i say return res i get the different shorter path right yeah so then i just go to the right and then down mm-hmm okay but i do want to return res here if i do less than equal to this it does do give something else uh trace show m okay and but it turns one earlier so you go right down down right right down right right right then it's 535 and instead it goes for after i think they may only turn left continue straight maybe there's some other rule that i'm not it's also just hard to kind of spot a wrong choice here okay let's see it should go so it goes 3 5 3 but it could go 6 3 3 let me see but here it goes um here let's go to the starting point level stop left destination give us a good one straight line for very long you can move most three blocks in a single direction before must turn 90 degrees left or right can't add as right against the email and left continue straight or turn right and that's all taken care of with his visited right so you're never going back what does it say for the input mm-hmm it certainly seems to be doing something for the input i'm gonna just check this probably too high i mean it's not like oh this one looks super silly right we print that to the d-box thing again and mm-hmm let's see so we have the path i am going to add 1.1 to the path full path okay and then i'm gonna say um get cheers and i'm gonna say x y crest is equal to um how to get how did i get from y to x x comma from y x um get cheers y res and then a get cheers uh the pv cheers equals a get cheers on reverse full path okay and um now i'm just gonna write here so we're not going to arrive show we're gonna say instance show dear where show up is equal to the up arrow okay this one show down is equal to v show left is equal to show right is equal to okay and then so here i'm gonna say case a c map dot bang map dot from list pv cheers yes d we're gonna say show d show v right so this is actually pv cheers and this is c and get cheers okay and then get cheers we just skip the first element okay then we go down left it's not as nice actually let me see this is the different letter is it maybe it's just uh mm-hmm okay we certainly have the we got a nice debugging thing going on that's something i'm still wondering what to so we go right right down right right and then we go up a instead of going right and up we go up and right let's say down right right right so instead of going uh so here we go up and right so we go it goes three and two and instead we go three no we go up one earlier so instead of getting uh four and three so we get four and three whereas this path let me see so it gets four one okay one yeah and then it goes five four five three but we go five four four three we go um we go uh five so here it here they're the same again right but maybe that's because now they can do three times here uh okay and we can't do that because we chose to go up earlier right and the problem here is that yeah there is a shorter path that um that still allows this so it's just this valid neighbor's thing it's just uh it's not doing it's not what we want okay so it's it's a complication right we did we did dyke strike correctly but uh we're getting a wrong path because there are shorter paths so i want to see this on the input it's gonna be nice with the updated version so we are too greedy in selecting in selecting the neighbors hmm maybe i can do something like uh that the possible neighbors are always just so not just the ones that are right away but also the ones that are farther away let's see and oscar allen knows yesterday like oh this is so easy but i'm not getting the complication right here let me see so um let's just start again okay let me get so let's go i'm gonna just take more steps every time okay a valid neighbors so i'm gonna take like three steps at a time um we just uh git commit git add day 17 git commit um day 17 partial day 17 not working just over there we have this code so now i'm gonna make it so instead of giving the immediate instead of giving the immediate neighbors i'm gonna say so the let me say take path let me say okay so so um all paths so it's gonna be um up down left right and we are gonna make a combination of these so i think what we can do is we can do x y z and do um x colon y colon z colon like this and then we just do like this like down left right mm-hmm up down left right oh and this needs to be a dollar now let me do here so this is these are these are all paths of length three okay and now i'm gonna do something different here i'm gonna say um i'm gonna say uh do okay i'm gonna say mb car parent of if we have a parent we're gonna say case mb current parent of nothing all paths okay so so we're gonna say here map so moves is gonna take a list of int int and a l and int int and a list of jr i'm gonna do int it moves it's just fold l prime oh i think okay maybe why not fold l a flip so fold l has type mm-hmm pretty much type there okay it's again i am forgetting fold l yes uh okay fold l and then do we have the list okay it was just the fact that so we do uh moves uh all paths right moves a map moves curve let x d ns equals uh no it's actually not like it's just map moves yeah so it's a final neighbor that we just cp let d cp equals from cp to curve in so we just want to filter um so we if the current previous parent mm-hmm i feel like i'm trying to do it again i'll just see let's just see what happens if i just i just return like this okay so first i want to let me see to let so let me see we do um we have all paths let me see f curve nothing is equal to curve f curve d ds is equal to is equal to uh curve apply to f ds um but we are going to say f move move curve d this is going to be map uh f map a p s is equal to like this in filter inbound let you say inbounds p p ks p filter inbound not last filter all inbound ps uh this should not be in of course okay so i will have here not any so we don't want any of them visited okay so now let's figure out the path cost path cost int so we have a list of ints and uh we're gonna give sd s uh thank you path cost convex is equal to so we're gonna do um map r r bang cs some okay um so we have all paths that are valid and let's just actually we want all of them to be in the bounds then let's just say um case so let's just see mvp is read ray parent curve okay so mvp of just p then let dp equals uh from p curve in r is equal to that we have to do this before actually so if there is nothing then we just to give all paths of nothing map f curve all paths in um otherwise we we return map f curve and then filter we're just gonna say not dot first equal dp we're just gonna remove all of the ones that take the same i think otherwise it would have shown up earlier okay now we have the all of the paths that are not and uh now we have the so we look up the tentative for the last of all of these and the current is going to be um let ds curve is equal to map plus curve is okay so right so here we are not gonna say read array x we are gonna say we're gonna say um yeah read does not let ds curve equals map plus curve is pass cost okay so now we have a cost of taking all these paths okay and now we are so we accept the ns here so let's make this actually a list and then we are gonna map okay so here if if we find a shorter path mm-hmm so we do write array disks and then this is just gonna be last of n and we are gonna say last of n here and last of n here but so here we took a path so then we are gonna say um so let f x y rest is equal to write array um so i'm gonna reverse it actually parent and we're gonna say y just n not just x because okay yeah so and f of and if we're at the end no right so this is actually gonna be x parent and y and write x is equal to write array okay so i'm gonna write array parent and then i'm going to f y rest but here and then here i'm just gonna say write array parent x just curve so now we are jumping three at a time error in array index do do do do and i have to do here filter all in bounds over this thing okay it didn't crash but it certainly did not do anything because it trace show ns just crushes right away it's because i didn't actually write any parents down here and i forgot to reverse here so they should all be inbound and you cannot let me see a filter dedupe so we don't want like repeats that's messing things up here and let me see set dot from list p a length p is equal to set dot size uh set up from list p doesn't work these are all the combinations of all the paths of length three okay yes all paths three and all paths two all paths one that's actually just like this all paths is equal to all paths one all paths two all paths three okay i'm gonna just i'm just gonna cancel this okay return map f curve f curve all paths so the parent of y no i reversed it yeah okay it's strange right because it's it's looping infinitely but then it's not let's see but then it just has the empty list right trace show m links rest what is it looping on this is not supposed to be curtest i think no so it is supposed to be curtest at the end of the past this end okay so it has to know so then this will just be empty right and this will just be empty uh maybe it's trying to reconstruct the paths trace show m td this target i was getting 99 which is exactly um this one plus the okay so now okay yeah so the path to the target is wrong i think um there's a like a loop in a path somewhere um so 99 is um it's exactly the length of the path so the minus the last one right trace show m m p trace show m p okay uh it's a right array parent so somehow 11 three became its own parent right and i think it's okay so we're rotten to visit it and let's see uh this should maybe not be okay let me see so here we all the have all the possible paths so here we just return nothing okay and here we're just going to say right array so the parent of y is just x and we are gonna say and i'm gonna say um parent right array parent add n just curl the first one should be a um okay now at least i don't get the uh because i don't do recursion anymore f y r okay i still get the and we don't need we don't need these parents and we just not to construct the path i think it's actually supposed to be this target um plus a target so now i want to just say that it die extra 2d i want to say it's a this target plus r r bang target so then we get the right answer but this you know this plus target thing is just something i just made up right but let's see what we get don't want to print so much out actually okay it's not finishing or the input the one we did before was at least correct it was just it was just not doing the right number of paths like the right paths like it like there were other options for paths okay let's just do git reset i want to grab this at least uh this one is cool maybe git reset uh git check out day 17 dot hs you know we're back to this point where we got the wrong paths and it's because we're too greedy here right we always say okay just okay it's been super long uh where we have die extra correct uh but we don't have we don't have the we don't we don't we're not doing the path correctly we don't have the right way the right um it's it's annoying right because we're doing part one and i think probably part two is not too hard or maybe yeah maybe it's just exactly the same mm-hmm so i could also generate just all possible paths right no that's crazy would make sense to generate all possible paths filter out legal valid paths and then uh mm-hmm i would at least get us part part one right if you just generate all paths but that's so stupid right and especially for the for the input it's not gonna work hey aphelix we have the breath for search got it up we just uh we are too greedy with the paths so it doesn't work what if i um just go the other way around mm-hmm going then we get an error in from and this one should be actually 13 13 so it doesn't crash let me see p-length uh trace show m uh sum so here we get 106 so we're gonna say um let a pl equal to to spl is this and then we're just gonna say uh trace show m spl minus r dot so we don't enter the min in it but r r dot if we do enter the target 107 then we at least get this initial part part right no no because we go here no but it's not we're still too greedy the updated path if you find another way to a node following path can be chosen better or longer because a new path does not have to reach the limit of three i i do update it right so it says here if the current is is less than the tentative this or equal to um then i update the path so it does do them but it still still gives the wrong path maybe i should not filter visited here we also not filter visited here i think they will look yeah okay and yeah no we definitely don't want to visit it yet visited here and is well rest and then filter not not set on member so you're only into visit it if we're like do you research the path after it or only update i mean so i don't look at anyone i've found because the argument is that if i get somewhere that is the shortest valid path to get there right do you research the path after it or only update the path to that no no i don't i don't research right because it's okay so what you're yeah so what you're saying is if i found a better path to a node then i should research that node mm-hmm mbn s let's try that so i will not filter visited and let's see so now i found let's see um if n set that member visited then trace show m and now sorry try let me see i mean so it's never the case that i hit that i found a new valid neighbor that i had not seen before it because you could come from a second direction to that node that with what allows you to choose a better path afterwards yeah but it's never the case right it's like i i i never see a node again let me see why don't i ever see a node again mm-hmm i should be seeing them again right visited curtists reiterates this curve so i get the distance to the current one let's do this here also yeah so it's often the case that i'm seeing again something that has a larger tentative distance mm-hmm you just do it this way so there and if curve but i think the thing is that it uh because it uses the parent arrays in when it's checking this one right what is this one one three three nine i don't get it make the three a four or five so which which three four and five okay so you want me to let me copy this then so what is the answer supposed to be here so this one here is not included as an option because that would mean i would have to have come up here okay now i'm sorry i'm talked about my example the one in the advent of code we're quite close though yeah i mean so i mean i know i know what the solution should be right so the problem is that the one here is not offered as a valid neighbor because we're coming from the left to it right but the problem is that we wouldn't be coming from left to it if we've got gone right here and up right so that's the problem so we can and it's just yeah so it's path dependent what the shortest shortest route there is mm-hmm that's the thing right it's not like i'm suddenly gonna come up to a point from some different route because i'm not taking any different routes like i'm just going the shortest route always but so i but route i've chosen shortest routes to this point here here is this path right this is the shortest valid one of the shortest valid paths okay so i guess i um let me see okay if it's like this uh curve just is equal to t just do and then just show m and return and current just okay so these are the nodes where there are two possible paths so then let me right change this parent list here empty let me see so right right away let me say a modify array parent and then n maybe that's straight away bear just have to do um here we had modify array the array the index so now we're just gonna reconstruct a path uh no let me see yes so then we're gonna say um okay um this is to to say that there are two multiple paths two paths to the parent mm-hmm let me see so these are curve parents okay so the valid neighbors so the possible paths here let me see and we're gonna say map m read array parent curve parents curve parent okay and this is going to be a list of list of ints so they so they have the possible parents okay and for each of those parents we have the list of possible parents okay so this is just curve parents so um let's see so the the possible paths to curve is a curve parents a p to curve we're gonna have here um so there's gonna be a reverse okay a curve curve no sorry the curve parents is like this so here i'm gonna have a zip with m no i'm just gonna have map m and then a cp and i'm gonna have read array the parent of that one so now this is the this is the list of paths and curve parent parents this is the list of paths to curve mm-hmm we see okay so cp is i think i think i get it now okay so these are the possible paths to to curve and now curve parents parents i want to want to do is i want to take a curve parent parent so all of the paths and this is a p okay what i want to do is i want to say here it's a read array of the last p and then we are gonna do p concatenate it to that right so we take the last of the paths oh okay let's see grace show curve parents okay and let's say let's map cp to a curve cp oh so we're gonna say over this map one of the parents we're gonna say curve cp so now these are the paths to curve and now okay we want to do the same here so curve parent parents so we're gonna say um so map m so we have the path here and we're gonna read array parent last p over curve parents okay let me see so we added the for each of the parents we found the last yeah and then we just map p to that i think okay so this is a path we find the rest of the path this is gonna be the same as this one okay and then why can't i map like this what is this ah okay so for yeah so i'm gonna add that to the this is gonna be the hit and this is gonna be t and then again no now it's too many curve parents okay so we and then we concat map like this and then we do it again so these are all the possible paths to curve paths to curve parents parents okay and then this is maybe that's curse is gonna be the an empty list trace show m let's just see what it is for the example okay then it's just an empty list good so now these are the paths to curve so the these are the ib's okay and i'm just gonna say move map move curve okay so we have the ib is here so now i'm going to say a pause nays is equal to um so path and new neighbor and we're gonna do dollar we're gonna say a paths to curve and we're gonna do ib okay and this is gonna be paths to curve so we reversed it actually no yeah so curves at the end here and then this is just so this is gonna be p and hospital name paths okay and then i want to say filter is valid or pause name paths where is valid what is valid is gonna do is first of all it's gonna find the the the directions it took okay that's the similar that we did here is this get there's function is valid so an empty path empty path is valid so now let's see what the actual path is right um like left there left right left right so ab turns x y this is gonna be x y x is is equal to um from how to get x to y turns y x is okay so if i end up with something this is gonna be you know from the first one to the next one here okay so this is fine so is valid p is equal to um is equal to case turns p of return and map last case turns p of um and then let's just say um x y set w x is equal to y is equal to set now let's just say turns p of um yeah okay x y set but they all have to be equal x y x equals set and x equals equals w false and you see i think and they should all be of length this length i think true error is valid uh i think i i know i mean i know what is wrong right the problem is more how to implement that a x is okay um 110 um okay so if path to car is empty if no path to car then i b return i b false let me see a oh and car parents okay let me see if any then return ib if knocker parents or so these are all the paths 2 1 x is case length x is less than 4 1 3 2 3 2 4 just see if I just scroll here but then it's saying that they like there is a valid path but we didn't take it let me just see equals a group in all so it says 2333 132333 and then okay let me see from threshold curve threshold curve parents threshold so we have 2333 and then we have so for 33 we had two possible ground we have I think something is wrong threshold I'm okay read okay and then read array parent curve trace show why does it okay so it has two valid parents two parents okay so I should not make it here I should have this as nope wrong with a concat map here okay I think I just need to concat here just concatting at the wrong level I think so one two one one parent curve okay threshold curve parents parents okay this is a curve and then parent curve curve parents if no curve parents or any null curve parents parents or no null curve parents or no curve parents parents so four three and so for four three we could have either come from we could have either come from three three or four two okay so that's three three or four two four three okay and then it's either uh then it's 233343 that's valid um I think I did it again here concat and again it's if null pass the curve return I B then else do let me see four four three something interesting right so for two two so now we're looking at um two three so the parents are two three are either so there are one three or two two there would have been four plus one I think if it's less okay if it's less then it's just curve and then it's just um right array curve if I find another path then I do the null curve so for 11 to 12 5 there's parents 11 5 and 12 4 and I could have come from 11 5 or 12 4 so apparently I could have come from 11 4 then 11 5 or 11 4 12 4 or 12 3 12 4 oh okay mm-hmm less than three okay I guess maybe I'm not I need to trace show again here I think trace show m paths to curve and then trace show m I'll pass napath and then this should be okay this is less than or less than four okay because they should not all be the same maybe this would mean nub dot sort don't you import that on your list okay so these are the possible paths let me see if I say less than three here then there is then should never be more than two right maybe because there is a possible path that's oh my god there is a there is an eruption in iceland not bad a and it is not underneath the town which is great means that the town should be fine for a bit well meanwhile I'm doing a bit of code okay so what I think is happening here is I am now writing all the possible paths but I should like Felix underscore five said I should I should let me see care parents care parents friends right it's good mm-hmm so that when I do when I do make a choice I think I should just return here I do return map last let me just remove this all these tracing if no no okay then there's nothing let me rewrite this valid paths take an int comma int sts in comma int and a we here we do return maybe with the paths we'll do this let I be a valid paths equals do a valid nays so here we turn nothing here we return nothing and here we return just okay but we do so we will just recalculate this and say valid vps is a valid paths curve case vps of just ps and then we return map last ps nothing return I be then then turn nothing then turn nothing okay so basically what I have to do here is I have to if I if I got there by a new path I have to say what does it say no we were still getting 110 and it's still not selecting that one there so the thing is basically that if I if I chose one of the paths to get there um so let me see here this is ns so okay so here I'm basically saying okay found a shorter path then I'm going to do a vps is um valid paths curve and I'm gonna say an ace vps of nothing then we just write is parent if I have some paths then I have to say let rps equals filter is equal to n dot last of ps and then we have the new path and then we want to say um f x y x is equal to write array parent x parent x the parent of y is just going to be x and then f y x is and then finally f of y is equal to so this will be n write array parent y write array parent yes and then f rps map m why am I getting so I'm doing the valid neighbors and then I filter all is valid okay then I can just map just empty write array parent and curve otherwise it's rps it's going to be one right in f rps so how can I have a I have the valid paths and I add the n to the end of it and then I filter okay and then 2 2 let me see uh okay the paths what so we have valid neighbors curve and it was a just it should be g really one one one two one three two three two two so here there are two valid paths either the one one or one two two three three okay which is to be expected right but I found right but if they are the same length that I really should not I should not change them right okay but because it might have changed the set of valid paths right mm-hmm I see okay so I have to just do here um rps and then here I write I don't write array parent so first first I actually let me say so clear uh clear x axis right is equal to right array parent x empty clear axis and then I want to fill them again I do um I do this nub dot sort sort dot nub dot sort dot x so we are gonna say here do clear map m clear rps so first clear all of them and then we update all of them and this is gonna be but they doesn't like this because it should be modify array in 113 and if there are no valid paths it's just because I'm in that in that uh easy case okay clear all of them and now I'm writing parent uh no the parent of y trace show m I shouldn't clear the map clear tail okay I did the clear but now it's still giving me the same wrong paths valid paths let me see ratio m bps maybe we should um okay ratio m and then I have the links paths I have it here p links let me see ratio m rps comma map okay so there are shorter paths the two of them might be valid but there are shorter paths let me see here reconstruct p um boss okay and then I'm gonna start reconstructing this I'm gonna say um I should really just be keeping the the last one right so after I've seen all of them what does it say that this the target is does it's the same actually I still feel that we should be getting closer here so we whenever we find a new path right we clear the old paths we just write the new paths so for some of them there are two valid paths let me see and what if I reverse these they'll get the same okay now I finally selected the right one and I'm getting a length of 905 which is the sub minus the target right so now let's see if I want to reconstruct the path okay seems like clear then I clear too much right clear dot tail of head I have seen so but once I I think I once I visit a note then I need to finalize the path to it okay um so then I do let me see um finalize let's do uh but the paths the path I take next depend on the current path to occur right up to rps let me just see what happens okay and this target minus rr let me get the right answer here and let me just do it for the input and I get prelude dot empty list what does that mean for valid paths so there's no valid next ones hmm what does that mean then okay so I'm having I'm looking at 15 comma two yeah okay no this is sorry this is the input 15 comma two is perfectly valid now if I have ratio and then n and n is what is the n is just so because vp valid paths curve and I map last ps right to trace show um what I don't understand how can this be how can I have a neighbors and I am getting so the valid neighbors is the valid paths of curve okay and then I do it again and I'm getting different results uh okay so because in the meantime the paths have been filtered out because I updated them so like the two two are interfering I'm gonna try this guess but yeah okay I hadn't even a better guess before let's just remove this 10 35 one last guess we have to wait five more seconds we guessed 10 36 we're still too high and it's also giving the wrong on the example given the wrong and it's because it doesn't pick this path even though now it like has the option to do that right let me see and get a socks um parent trace show m so one six this is one ten the other way to reach 110 is one nine it's the one the way we do it or age three four there are two ways uh you come from two four or three three so if you get the pause let me see we do um map reconstruct path pause map and reconstruct reconstruct path these are going to be many path reconstruct path uh taking an int comma int and sc s in comma int so two and let's see um so this is gonna be a list of list of things and we're gonna say map we're gonna be doing the same thing as here I think let's see and so concat map m p map t p over reconstruct path um you see I think I what I do is is so I do um I do map and reconstruct path pause pause prime is gonna be a list of list of lists okay so so for all of these lists I'm gonna do map there's gonna be a list of lists map curve okay find stillpads but they are both the same so and then f here is um path we're just gonna make it do all the work as pvdirters is is actually gonna be taking the paths paths and now we're gonna say um and now we see that there are multiple paths and they differ but they just go slightly differently here but it's not allowing the other one but maybe I should just always modify the parent let's I find a shorter path I modify so here I'm just always adding parents we see trace show m curve it's just looping maybe trace show m just target I get 78 okay another is clearing business where do I get so then you get so then I always get all the valid paths to a node let me see so this is the same as when I had the when I didn't do any of the filtering let me see these are the valid paths for all of them okay so one one can be reached by one two and two one this could actually be the stupid stupid way to do it right so here we get all the paths and then we can just show the minimum path lengths like it's not even working for the example right and it's gonna give us the shortest path which is the distance the problem is that um this one here one nine it says it can only be reached by two nine but you'd also be able to be reached by one eight right why is it doing that wrong it's because so one two can be reached by one one one okay let me just see okay so the problem is that we go to this three four so this three here can be reached by going up like this this three should be reachable from to one seven should be reachable from one six one six and two seven so one six one six hey Chris I've been coding now for two long six hours but I'm not making it's not happening so one six should be reachable from so it's saying one six is reachable from one five but one six you're also reachable from two six what is it saying about two six two six is reachable by two five wow follow so now we get a one six is reachable by one five one seven and two six okay and filter not dot flip set dot remember visited dot last now I'm saying 102 96 it's saying if I add the parents and I filter the visited the paths are all wrong mm-hmm okay generates a lot of paths at least some of them have the right links I'm gonna show the shortest path it's almost there but it does allow this multi group thing right p-links I went to a University of Iceland and then I went to Chalmers which is good trace and let me see we're not interested in this let me see sorted is equal to sort on p-links that's so we do head sorted and then we do trace show m map p-link sorted okay so here we are getting the right path trace show mp p-links it's for it okay at least it finishes for the example currently gonna be crazy slow for the input but let's let it run mm-hmm yeah it's missing one put string at the end and to show the bottom one now it's basically just creating all the paths and we try and make it a bit faster we can say here paths and I'm gonna say here filter is valid paths I need to do it a bit later and you can kind of throw out um invalid paths right away let me see did this make the main thing slower actually let's see let's see mm-hmm okay this is not gonna finish anytime soon so I mean at least we're getting the right answer now or the example we are doing it super slowly and we could probably do it in a better way uh we have dikstra's algorithm coded up but we are just not able to kind of make it take all the valid paths in a nice way so I'm gonna call it a day for now I've been streaming for like six hours or something and we're gonna let this finish call it a day and uh yeah keep trying tomorrow but oof this is a difficult one I I don't know why everyone's saying like oh it was so easy I and some thing I'm not some way I'm encoding it is that I'm not I'm not able to make it work all right but thanks for tuning in sorry for how extremely long this was and see you tomorrow where we can hopefully finish this all right bye