 All right, I Said two minutes So anyone went out for a drink or whatever Let's give them a couple of more minutes, but Then we're gonna move on with day 12. I hope day 12 isn't too hard But since this was quite fast, I mean, I think we're I think we're good Let's see Do All right, I think it's been approximately two minutes Let's say Close all the array stuff But I like I like a bit of code in this sense, right? Because now we've seen, you know, how to do mutable arrays You've seen how to do parsing and we've kind of get a gotten a kind of a nice glimpse into, you know Like people always think, you know, how would you do this in a functional language? How would you Like how do you deal with immutable data is if everything is immutable by default and you're like, well We have data types for that. It's just like instead of mutability being the default we make it explicit Which fixes a lot of places. I'm gonna get some coffee and then we'll start I Keep pushing the keep warm button on my coffee maker, but then it just doesn't do it So slightly cold coffee, but hey I'm somewhat of a bad coffee aficionado you know, I Just like coffee and then bad coffee is not as a best coffee, but it's not too bad either Let's go back to Admin of code. Let's go look at day 16 not open yet day 12 Rain risk. All right, your fairy made decent progress towards the island But the storms came in faster than I never expected your fair needs to take evades of action, right? Fortunately the sips navigation computer seems to be malfunctioning rather than giving around directly to safety It produced extremely circuitous You see how I pronounced that word it was a magic card So I had to think a bit when I was playing magic about circuitous route Circuitous circuitous, that's how I say it With the cat in use of the PA system To ask if anyone can help you quickly volunteer Navigation instructions your puzzle input consists of a sequence of single character actions paired with integrable values After staring at them for a few minutes you work out of the problem mean and it's north south east west left right forward Okay, so Action have means to move forward by the given value in the direction the ship is currently facing Ship starts facing east Okay So north So north will always give us north so we can kind of we can kind of Take the north south east and west instructions out in the beginning Okay, let's start by Let's start by doing that. Okay Do-do-do-do-do-do, so I mean we we we in essence we have a bunch of instructions and we have to translate them to the right instructions Let's do it. I'm just gonna go do text dot parser combinators Repeat look at this written by My arch nemesis Let's look at it day 12 oh it went into the wrong directory No Thank you Do not ask me again. That's very harsh, right? new file Day 12 dot HS All right, let's see a Import no, this is gonna be module main where Import text dot pars parser combinators dot repeat I'm not even gonna write a parser. Okay. I'm just gonna say Data So it's gonna be what do they call it? Instructions right now it's gonna be It's gonna pay north north-int or What put in the order north-south east-west? South-int east-int west-int And then it says Then it says Left right forward right left and right in forward Now I'm curious Well, will it only ever be r90 or like will it ever be are something that's not Go to turn it into So, I mean it seems like, you know, none of them will be like r45. See r45. No, no l45 I think they'll always be Just flipping in the new direction That's gonna be fine. Okay Deriving, okay. Now you write to instur Take a string and write the instruction What's the type of read So if I want to import implement and read instance, I can write read sprek Read sprek is in streets s. I read as it's just a list of strings. This is just it. Okay, so instance read Nam where I'm not allowed to do this. I need read sprek. I'm just gonna ignore this. This is gonna be the string and I'm just gonna Write it here If it starts with north and rest Is it gonna be and Read and dollar read our comma Like this for all of the data types s s e Oh shit, it's not. Oh, I didn't do the thing. Okay so and s He Oh my god, let's See, this is the difference between whim And vs code. Are you ready? We're opening this file in Vim Now this is a wrong directory day 12 Vim day 12.hs I'm gonna open it here and I can copy These and I can paste it Here and it and it does the correct thing if I did this in vs code. It would like paste each of the lines Which is super annoying. Oh I copied too many like this. Okay our f Okay, and then get input is going to take a file path and it's gonna return as an IO of a list of nav Get input it's going to be F map read dot lines of Read file. I think I have to do map now main IO main equals yet input test input into print So you Chrono Kirby and Timmy How long did this run for you to Was it a lot of work? Like what is the what is the baseline here that we're competing against I think actor competing That we should evaluate ourselves against. Well, I'm gonna say here GT Oh three day 12 measure command Expression D12 Default We just parse it and print it All right F10 North 3 F7 R90 F11 Now we're gonna write a function here is dear it's gonna return now to Is we're gonna derive enum Is dear It's gonna be an Is there is gonna be LM north So no, okay This is too too brutal because we don't we don't have a north south east West Okay solution. So we first of all we're gonna take a list of nav's and we're gonna return an inch Solution, okay Undefined now we're gonna say here where span We're gonna we're gonna text Google we're gonna split into two lists the instructions The span what is it called again like the not the span but the other function Like the one that breaks it into two groups and Drake drop while split at Okay, let's So it's gonna be here. It's gonna be tears comma There's gonna be directions and this is gonna be the other one is going to be Instur and this is gonna be Filter is dear That's comma filter not is dear I Now for the nav's We can actually just sort them we could do like we could do We could do imaginary numbers. Let's see a can we do complex numbers in nascar? Is that even wise let's just do it now let's write Dear to complex Board data.complex It's gonna take a nav and you're gonna return as a complex dear to complex on north And that's gonna be And plus zero now, that's gonna be oh, no, sorry, that's gonna be zero plus and Dear to complex south and so we're gonna be zero plus minus and Dear to complex East It's gonna be n So this s s E and e and then West West is gonna be Minus v and you're too complex anything else is just gonna be undefined Now can we we can some right? Let's see here Whereas see It's gonna be the sum of map dear to complex of Dears after to complex and this isn't why why do you define complex numbers? If I can't add them that is That is useless Some complex numbers has cool. Okay, so then we just write fold L one C1 C2 is it goes to Okay, let's just see here This is a Plus v plus x plus y Hope Santa's fairy doesn't end up somewhere imaginary It's Santa bro, he's going to be imaginary But how how how did you solve this to me a plus x Plus a v plus y Dears. Oh right a Map dear to complex Okay, now we have a final coordinate and Let's see here. Let's see magnitude Magnitude of Red Sea And that is Real float into we'll be working with floats But that's okay. We get the input and We will print solution So this will be the They kind of the result after After If we only look at the directions Non-instruction non exhaustive patterns in function is dear. All right Gotta I just had two ins for x and y. Yeah, okay, so we go north up three I'm yet up. I mean it's like we use polar coordinates, right? That's what that's what the space people do We're gonna be like astronauts Using by look got complex Okay now we have to figure out now you have to Now you have to figure out this for forward ten oops, oh My god, no This is all the input it's gonna be a lot of input and I don't have access to any of my commands anymore. That's fine No, I have some okay Can I get an F in chat? For my terminal history Let's see The thing is like it starts with east so so we're gonna say Make polar let's look at that occur phase Starts off and the current phase starts off at zero now Now we're gonna we're gonna go are the instructions We're gonna make them into complex coordinates so we're gonna say a Instance to complex that's gonna take in a list of Nav It's gonna take in like the the phase which is gonna be a float and a list of Navs and Instance to complex it's gonna Instance to come it's gonna take in the current phase and a list of Navs And it's going to return a complex a float Instance to complex a phase So if it's if we're just gonna say phase Nothing, so if we are for the end No, let's let's use And then we're gonna have another complex We're gonna have a complex float Okay float complex float nav complex float So curve phase Thanks and Steve TV Hope you all are enjoying some Haskell programming It's I like it Curl Oak and everybody empty one then we just return curl Oak Now insters and it doesn't matter Insters to complex of curve phase Curl Oak So if this is the case of this is F If it's the case that it's If it's like our okay, we don't actually need These are to put the P. We can see it's gonna be it's nice Now these two these two will be in So if the current phase of the look is so we're gonna have a couple of phases We're gonna have our R 90. We're gonna have L 90 and 180 so R 90 rest equals That is going to be insters To complex of This will be cur phase Let me see So, okay, we're start off in east and then we go right so okay Let's go do that one if we go left 90 then the current phase goes up By pi over two Okay, if it goes left 180 Then it goes by Hi, if it goes R 90 Then it goes Because R 180 then it also goes plus pi So that's gonna be fine, but if it goes right So because good doing plus by a minus pi here is the same because it just loops around R 90 is gonna be minus five. Let's just have it minus five. It's gonna be fine now insters to complex a So cur phase and cur look Okay, so now if we have And so now we're only gonna be looking at forward and Magnitude rest It's gonna float That's gonna be That's so then we're gonna create a new number We're gonna say Where X plus Y equals Make polar Make polar M Cur phase It's gonna be insters to complex Cur phase and now here we're gonna have Cx See why Cur phase is gonna be unchanged But this will be a Cx plus X a C y plus Y I Think this needs to be a bunch of parentheses Right Let's see if it works It's gonna be magnitude a res C Plus insters to complex Okay, so res Instur is going to be Okay, so But this is res C that's gonna be are a Rx plus ry and now now the It's gonna be the a dx dy It's gonna be instruction x plus instruction y of Applying insters to complex and we start at zero current phase is zero. We started this current look zero Current look zero zero plus zero and We give it the inster and then we simply return the magnitude and then res equals dx plus I x Plus dy plus I y like this and we turn it to magnitude of res Let's see. I Really, I it's a bit sad that there's no native support for 18.78 Okay, that is not That is not correct. Let's see Laugh 90 So it you can return all the instructions So we just have two ints. Oh sheet. I flipped around wait now make polar magnitude In the current phase right Let's say data complex It's gonna be magnitude in Yeah, yeah, yeah, this is correct Okay, let's return Complex float here. Let's return the res. Oh, yeah, so we're gonna return the Manhattan distance of 17 plus 8 25 So the magnitude is like going there directly Yeah, it's goes gives us a Euclidean distance exactly to me Timmy has it again Let me see so this is just gonna be abs of dx plus I x plus ABS dy plus I y right all right 25 point oh So that was that's correct, right? Let's get the puzzle input. Let's see how it performs on the input Okay, 48 milliseconds. Oh, no Non-exhaustic patterns in function insters to complex. I apply them to what? So we have a burn out line a L 180 R 90 R 180 Instars to complex and then whatever whatever. Oh Yeah, no, okay, and then our arrest Because her sure are Let's see. Well, let's see what it fails on L 270, okay Yeah, okay, we have L L 90 pi plus two L 180 and then we'll have L 270 which is gonna be pi three times three times pi Over two and the same for R. It's gonna be 270 It's gonna be three three times pi 42 Make sure that the braces are correct 319 point zero Oh my god, okay, I'm just gonna write 320 Because I think this is some floating point bullshit. Oh my god Okay, let's see. What's the result? Dammit, you know, what is this? Is it like? Okay, we're gonna have to just rewrite it Let's rewrite it Let's drop these complex stuff. We don't need it A comma B it's gonna go to A comma B it's gonna go to these are gonna be ints And we don't need dates wasn't really counting on floating point errors You don't have to deal with them that much in Askelion, you know, they just don't quite show up ds plus ix Plama is too too complex now. This is gonna be A little bit from me if you're gonna say, well Insta Don't mind Actually, let's let's change it. Not quite there Let's keep these as complex numbers But let's change these to int And now this return on a complex int Make polar Won't work What can I just have this be? int Well make polar well Only work for floating So if it does L x Curve phase plus x now if it says R x We are going to return x and then When we have this Uh curve phase x plus y case curve phase of Zero then it's going to be We're going to the east is going to be cx plus m ci Which if it's 90 then we're going up if it's 180 then we're going backwards 180 and looking at packets linear linear v2 Oh, yeah, that looks good. I mean but kamateza He is a real legend, you know Yeah, then you can do oh, then you can do some of vectors Oof, but also this angle Needs floating Yeah, I wish I'd known about it before I started today I I concur So and always here we will do We do the current phase plus x mod 360 360 Let's see. No, this won't happen I mean it might happen, but I don't think it will happen. This is not 17, right? so, okay zero 90 180 270 and then 360 No, okay. Yeah, this is just supposed to be nx plus nine Okay, now we get this 198 plus minus 121 So then we get this 300 we get this That was like well, it was almost all we got before right, but this is fine 319 let's see We said 320 earlier, right? We should just round it down. All right We got part one Now, let's see what part two is going to be about Uh, before you can get this you realize that the actions actual action meaning we're pretty on the back, okay Almost all the actions need to get how to move a waypoint, which is relatively just Rotate the waypoint around the ship this uh I am going to save this as int version I'm going to save day 12 adages day 12 Hint adages I'm going to go back to the floating point version Because I think that would be way better for doing any rotations and stuff like that We're gonna do all of these things Oh, shit, that's too many undoes and we just run it on the We run it on the input I forgot yeah, I this is I didn't have the number two To 70 and then R minus Let's let's replace the double float with double It's gonna make it all slower, but that's okay. Do we get the same errors if we don't have uh Yeah, I mean, okay, so the error will just be smaller Okay, like this and I will just use this and now instead of saying We will say We'll just round it I'm just assuming it's close enough Let's find a dag to rod into float Dag to rod 0 equals 0 Dag to rod 90 equals pi or 2 Dag to rod 180 equals pi Dag to rod 270 equals three times Pi or two Uh Oh, this is not supposed to be here Change this to be Something more second D Let's dag to rod to D And then for R It's minus much clearer Sweet Okay, and It's probably this function exists somewhere What we could actually do is like we could merge these two, but that's I don't think I don't know Oh, let's commit it Get status And day 12.hs and then input and test input Hit commit a m day 12 Part one Push it I like I keep saving my work. I keep just I'm always pushing on git Usually like if I yeah, so I usually you know, I have my own branch I just commit a bunch to that bunch and then I push on the branch and then Afterwards I fix it up, you know, I merge it to merge requests for the branches Uh, but this is It's nice Okay, so It starts at 10 unit east and one unit north relative to the ship The waypoint is relative to the ship that is if the ship moves point waypoint moves with it So F10 moves the ship to the waypoint 10 times So 100 units east and 10 units north So what I'm hoping is, you know, if we have the complex coordinate, we can like rotate about the coordinate No, I mean you don't really have any So to rotate the imaginary number You just change the face so then we We move it and we rotate it. Okay Oh, okay Let's start this is gonna be something right So we move the waypoint north and we move the south east west. Yeah But now we have to kind of do it on the fly Because uh, we can't just like we can't take it out Okay, let's see. Let's see No, let's just move. Let's see here. Okay, let's see. Let's see what happens Volition to now instead of doing these We actually need to be instead of this we will just say abs x plus abs i y And now this will be And abs okay, so The current phase Okay, that's gonna be the face of the waypoint So every time we move so we move the waypoint and then So, okay instructions to complex. Okay, we have the phase We have the Ship look and then we have so this is gonna be s ship and waypoint We Then we return in the end. We return where the ship is complex Float and this yeah, they have different numbers on argument. So Let's call this a rot and then ship and then we Wait a point Okay Plus deck to rot Now we're gonna be rewriting this anyway. Okay if we're at the end, we don't care about the ship Uh, now let's just call this run actually Okay, so if we are in the end and this is gonna be then So we start at 10 the waypoint starts 10 units east and one unit north relative to the ship So this is going to be the position relative to the ship So The current Faye the current rotation is a rotation of the waypoint so I In the initial rod We don't need the rotation. We just need We just need the position of the waypoint Okay, and now this is a so the initial position of the ship is zero zero The initial position of the waypoint Is 10 units east And one unit north Complex float Okay, uh, so let's see ship Okay, then yeah Ship and then we pee and then okay Now for n So the magnitude These are all floats. These are ints So the n magnitude We move the waypoint north by the given value So this is gonna be v x v y Rest First of all, then we are going to say there's gonna be run The ship is going to stay the same place But we move the waypoint v x plus m plus v y Rest Okay now for south We will remove the waypoint south Um For east and oh, let's do east first No, no, no, this is this is this is wrong This is east and this is west and this would be north Uh North magnitude that should add to the y coordinate y plus m and This should be and then we have moving this south This is going to be y minus m Okay now Let's let's do f though f means move forward to the waypoint a number of times equal to the given value Now that means a run ship Weep we Of if it says forward Forward magnitude rest It's going to be run Ship prime The move point doesn't move and the rest Where ship prime Then we want to uh, we want to You compute the new number Okay, so uh v p v m v r equals polar v p right v m v r and then a This is going to be uh n n p Uh New look it's going to be a mk polar mk polar of v m times m v r so that's that's like The position of the ship relative to the ship where it's going to be moving a rx relative x and relative y And now I wish I could just add these two So let's just say s x plus sy is going to be s sx plus rx Plus sy Plus ry I think Then we moved forward in the direction of the waypoint Relative to the ship now, I think actually That left and right Are going to be very easy ship vp left wrote It's going to be vp prime Where vp prime equals That's going to be vp prime. It's going to be the magnitude of vp We're going to make polar Polar with the same magnitude as a waypoint But the uh the We're going to have the phase vp plus dig to rot of the the rotation Doesn't look too bad, huh? Using polar coordinates Rotations of vectors and stuff. Let's see what let's see what it does already pushed 274 for the test input But it says 286 Let's inspect the float This would be a complex float So it's 126 plus 148 Okay, let's uh Let's see here. I want to show this Our assembly access space here should be this is how like this slightly more concise More aesthetically pleasing as you Import debug without trace this needs to be at the top Okay We're going to say here trace show trace l l uh l plus d trace All right Trace is going to be we're going to trace show Uh R comma vp prime If we be all right, okay. Let's just say you are here also trace show R comma Ship prime Ship prime Let's see what it does for not for this one But for the yeah for the test input. Yeah, let's see That says Over 10 The new one is nine 99 plus 99 So leaving the ship at east 100 north 10. Yeah Okay, let's let's actually change this Let's make this a die. This is like the instruction right Where vp prime is going to be this number here And here we're going to show i comma vp prime I No, we're going to return the vp prime Yeah, like this So for south it was minus here for this it was plus m here It's east and then for West it should be west minus you're just joining us. We are doing Day 12 of the advent of code for 2020 Uh, we already did day 15 earlier today But Uh, we finished it quite fast So we're doing day 12 because we have to catch up because I missed out on day 11 day 12. I did day 11 yesterday Now we're doing day 12. Okay, so North so f 10 says go. Yeah Okay, so move the the f is correct and three moves of 8.3 units north Uh three two to 10 units east and four units north of the ship Yes, okay. So then f 7 Move the wave one seven times 70 units east and 28 units north Uh, okay, I think it's just because I'm adding it Wrong here, uh, so Right, so when when I So that's this thing right so n three f seven Most of the way point seven times so f here Should not do the polar thing It that that's too much. Yeah, so it should just be A the ship x Vx a Plus a we y and this should just be Plus m times and this should be plus m times and this should be one we y way And then okay, let's see if this works some bug Vx we y Vp at Let's see. See if it works It's running at least that's something okay, so North ring was a way point then f seven Leaving the ship at east 170 north 38 Yes, okay, so that was right. So the f was right So then let's do the polar thing, right? Okay, and then it says Okay, so it moves it depends up at 170 north 38. Yeah R90 rotates a waypoint around the ship clockwise 90 degrees Moving it to four units east and 10 units south leaving Four wrote four units east and 10 units south But we're we have it at four units Four units west 10 units south Did we just rotate in the wrong direction? Yeah, okay, we forgot when you fix this we forgot to change this to minus Let's see. Let's see. I think I think we got it now Yeah Yes, so then we rotate it and it ends up at four and minus Minus 10 And 10 units south. Yeah. Yeah. So yeah, south is south is down south. Yeah Which we're in the polar cord is more than not in screen coordinates, right? Okay, so And then we move the ship and it ends up at abs They should be correct. I want to just define I'm just gonna do it like this Instance num complex float where This is Flex any flexible instances for this language flexible instances I probably needed something else also right. Yeah overlapping instances for num there's There isn't there isn't one already So I don't have to do this. I can just do ship equal ship plus 10 times vp ship Oh sheet Oh, wow. Okay. We didn't actually need to do this Uh m times vp from integral Because this m here will be a float, right? How do I change it? Return This is a function that goes from float To complex float Yeah Yeah, so I need to you need to So this should be a Make polar m zero Does it still work if I do it like this? Yeah, it still works nice so This vp here that's just going to be vp prime is going to be vp minus West is minus m Plus zero So it's going to be this is going to be vp is this Because we don't need to like pattern match or anything I like the way I like writing it that way better We put so much effort into Defining all these All our coordinates, but then we didn't actually have to do anything You just write zero here, right? And I think like we could write m here. No, okay, we have to So north and south That's they're gonna go from zero Plus m and it's gonna be zero So M and it's gonna be minus Okay, apparently this works also even though I don't know. I don't like how it reads Because it looks like kind of like zero times vp, right? Okay, but it works right Then this here This is just uh So Yeah, I think this will do it Do All of these change the vp Um And you can see that because we use puller we use complex numbers and polar coordinates like we didn't have to deal with the whole Rotation stuff, right? It just works I like it Let's uh clean it up because uh Complex numbers, you know, I did I did math Math not even one skins Uh, they are essentially Just a vector They are not essentially they're literally Do a vector That's how we do talk about the complex numbers and then you know the whole eye and imaginary that is just That is just lies put on later I think that's what I think this all changes the The way point somehow I wish I could like there's there is a number I you can Uh, there's like you couldn't Uh, I think you there's like a there's like a number you can multiply by Oh shit If you multiply by I If you multiply by I then You you get You get the rotation, right? Let's see Uh, so instead of saying here make polar What I want to say is I want to do vp times So, uh Deg to rot I want to say make polar one Deg to rot D and this should be magnitude here should be Minus No Deg to rot should be complete, but this should be minus and we end up at 274 Which is not 286, right? No, yeah This is this is still giving us 286, right? Yes Let's see. What if I Okay, so in the test input I have r 90 so I only need to be changing this if I want to see what it what effect it has So where vp prime equals vp times Uh, I want to do d Like how how many times oh my god d div 90 So this is how many So this is why that is not correct Polar d div 90 times Pi over 2 Make polar Make Polar and what this is you here Couldn't match type. Uh, okay. This should be 1.0 No Here I got 274, but I see we get 286 Magnitude should be a positive number Uh, oh, yeah, sweet. So here this should be positive No, we don't need this Deg to rot thing and we don't actually need these Here well, okay Deg to rot is Going to be need this this is going to be minus Deg to rot d And this is going to be Deg to rot. Do we need all of these? And this we don't need these here. Okay. Now, let's see. Let's see what happens sweet You see So now Um So for all the things Uh, so now I want to uh No, I want to just yeah So we could we could map these all into changes, right? But now we're just using complex number math To do it directly, uh, which is nice So Uh See that's going to be where this is cxcy that's coming from That's the ship It's going to be c plus r Or rot I like it this way now. Let's see. What's the solution one give us? Because we're changing that up a bit too, right? That gave us 25 Which was yeah, that was part one So let's see here curve phase We don't actually need to change the current phase, right? Oh, yeah, okay. Yeah, we need to because we're just rotating the ship. We're not rotating like the entire Are we No, yeah, we yeah, okay. This is good Let's copy the dig to rot from here Picks this up and make it more general How can we like make this a bit nicer? Can we make it a nicer at all I like this. Uh, it's pretty second, right? assistant second Yeah We don't need this Now, let's let's we have this is dear function, right? Now, let's let's write a Dear to move Yeah, it takes in a nav And returns a complex flow Here to move so nm is equal to zero plus a now sm is equal to minus East is equal to m And This is west Now we can just say here Run ship vp I rest Case is dear I equals run Ship vp prime run ship Vp plus dear to move a I Rest we can move all these lines These are all doing the same thing Ince This is gonna be ince Okay now Dear to change it's gonna be nav complex complex float Dear to change a Ld is going to be Make polar a 1.0 Deg to rod d and then R It's gonna be Deg minus Minus take to rod These are all non-tool functions So we have is dear and then we have So we can do it like this if it's a dear then it's like this If it is n then we just move it otherwise The ince here is going to be ince It's going to be this so then we just say vp Times dear to change Ince because if it's if it's not if it's not If it's not a direction and if it's not like an f then it's going to be a rotation and this is going to be I like this specification of the thing So here we So it's going to be we're going to be multiplying or we're going to be adding and so Dear to forward It's going to be nav to complex Float Dear to forward it's going to be ffm is equal to um M0 ince run is zip plus forward Ince But here we have to check is a Is a forward is f. Let me just define Is f to be nav to bool is f f equals true Is f underscore equals false So it is a if it is a let this just be you know, this is dear. Otherwise, it's a rotation So this should be a Dear to move this should be a rot to change and this would be f2 So this is going to be is f Ince And it's going to be a f to move and this is going to be This is going to be to change Okay Now this is a very nicely put way of doing it now Let's see if it's correct. We haven't actually checked We've just been refactoring all day every day 9563 Seems to run pretty fast. Uh, let's see. That's not the right answer. Damn Oof Did we do something wrong in our refactorings? We still get oh now we get oh, okay. We don't we don't get We don't get it correctly. Oops Uh, this is why you have to have tests, right when you refactor Let's see. We yeah, we should have checked if we had it correct, you know the tests output Okay, that's wrong. So if it's a direction Then Then it's then we change the VP by the direction to move It goes north Then it goes north goes south goes south east goes east where it goes west the left rotation right rotation Uh, no, wait, this is this is wrong. This should be F to move times VP I think that's the issue here. Yeah, now it's Now it's saying 2086 and 319. Yeah, now it's correct All right We finished day 12 And we did it all using nice complex math Uh, I like this I like this solution I like uh, because it's like it's like succinct. It's uh, you know, we didn't have to do any pairs or vectors or anything like that we just Kind of directly We kind of directly, um Fixed it we did we did it all directly, right? All right, and we did it, you know in 732 milliseconds for all of it And I mean that's not a bad That's not bad at all. Let's see. Let's see What like only the part two of the solution picks Not very time complex this task now exactly I think it's also, you know, because this is mostly about like Can you make it look nice? In the thing, you know, because like I don't think there's any shortcut here I don't think like okay. We did take a shortcut in the first one here But that's that's it, right That was it. That was like the shortcut we take took That we could just we could just move the north south first and then Use that directly Uh, but yeah, this is this is quite nice So first we we change here we change the Here we change the VP here we change the ship here we change the VP again Yeah, all right. I mean I'm getting 23 milliseconds just barely more than starting I mean this is this is Yeah, this is not The actual time This is like this is the time that it takes when I run it first right and that's always a bunch Yeah, so it's 33 milliseconds Yeah, I'm not I mean I'm not spending time on anything right so It's just I don't know it's like The runtime system has to load a bunch of libraries or something and in And You know, I think I think it's just like the runtime system has to load a bunch of libraries And And At least on windows, you know, I mean those libraries will be in the cache When you run at the second time I mean, this is why like amazon lambda functions. They always warm up first and make the machine warm Is yeah, I mean that's what I would assume it's like it's some like first It has to read the definitions and everything from the runtime system into the memory And then because that's like a couple of megabytes Like the runtime system the executable itself is like 80 megabytes compiled and it hasn't like load that and but you know, I I don't know because like when rust When rust people run it it goes fast Uh, but like I don't think they're doing time on the command line Like when I when they say we do it in a couple of microseconds. That's I think that's like after Reading all files from disk because like microsecond read times of files. It's just that's way too fast for me. You know All right, so Yeah, we did day 12 Uh get commit Let's just remove the int solution. I didn't like that rm day 12 Dash int rm star and then this is because we opened Vim Get status Get commit a m Day 12 part 2 Yeah, this is pretty nice So I guess Tim you did this with pairs of integers like you had a bunch of issues doing Like rotations and stuff right you because you have to figure out the rotation of the coordinates and that's a bunch of work, right? That's why I assume That's why I like this complex number of stuff because then we could just use you know times and plus and multiply To do all the rotations And it just works right away. It goes fast I like it. I like it timmy Hey And uh, you know, we could probably do this nicely by saying here Instead of saying float we would say this is a complex number And then we wouldn't have to Do so much here. You know, this would just be like this here is essentially Let's let's do here Uh Data change is going to be Let's do uh, if it's the waypoint complex float No, so this is going to be a deer And then it's going to be a rot complex float And it's going to be move complex float and then we just do deriving show Then write a function Taking all of these Here when we're where we're going to say, okay, this is going to be the function We just want to be so if I was like writing this actually it would be like A nav to change takes a nav and returns Change And now nav to change is going to be all of these right to change Uh, this is going to be these are all going to be deer Actually, I don't need these Deer applied to dollar Let me just answer one message Okay, uh nav to change then For these it's going to be uh, no this is going to be Rot and then finally It's going to be And now we don't have the Dag to rot function anymore. So we have to go get it To rot just going to be this Okay, now to change dag to rot Uh, then we just do here And we are just going to do So Changes is going to be map nav to change Naves We don't need these Uh, and then Chit-chit-chit-chit changes Uh, so changes is going to be a list of changes Change that was what obama said, right? Oh, okay. Yeah. Okay. Yeah. Yeah, sure I think you know for us we we could have dealt with non non rotation not like degree rotational stuff, you know So if if it is Rot of R Then it is vp plus. Uh, no if it is Deer d then we just say vp plus d If it is rot to no, so here we say if it is Rot R and then we just say vp R and if we say move m And it's gonna be ship M10cp Pretty nice, no Map nav to change naves This solution is pretty short Let's look at timmy's solution Yeah, I mean it's good kind of the same, right? Uh, but right direction. Okay. Yeah, this is nice To have direction as one thing and then Then you can kind of match on direction instead of yeah It's clever timmy very clever I see so now we have okay now we don't need these is dear So what I like about this is now we have no non total functions So we don't have your filter or anything, you know, oh we we do need dear here So we do it we do it for a solution one, right? Why we don't do it for anything else Which is nice Let's run again now solution two is like super short Um and runs quite fast And it just works out You know, I think we could rewrite this as a fold somehow by like encapsulating the state in like a pair And then it says pair to pair and then fold over the pair But you know, this is just fine. I think it's quite fine Let's uh, let's see Yeah, so I think this is quite nice quite this is for quite fast It's very detailed Uh, and the solutions themselves are kind of easily expressed, uh, which is nice All right, um, I think that's gonna be all for today. We did two days today get commit him day 12 refactored Refactor red push Yeah, that's gonna be all for today Things again for joining in I had a lot of fun doing this. I like doing complex numbers Because they you know, I know that works Got to use So timid solution is like, uh, I think this is a like a proper pattern Can you even see this? You know like where you Where you have, you know, you have two fields. So I had like one field Uh You know one field encapsulating the entire thing, but Timmy has the direction here Which means that later um He can define these a Functions on the direction itself And then he can like look at the direction here, you know Which is It's good It's good stuff timmy. Yeah, and exactly like because the Because for timmy He's just using pairs of ints and you know, luckily, you know, the changes are all pairs of ints So it all works out But we use floats because we're using complex numbers And you know, it interests is some floating point operation errors, but that's just because the default float in handschool is like 16 or something That is it's a weird choice, but you have double which is like oh like yeah float is like 32 and you have double which is 64 but uh Yeah, I pushed it and uh, thanks for joining in and uh, you know Look look in on the youtube channel. You want to see the recordings or on this channel And uh, join us tomorrow Five o'clock tomorrow. Uh, we're gonna be doing day 16 It's gonna be good And i'm still in quarantine so You know, this is great Great to have something to do quarantine. All right. See you all Tomorrow. Bye. Bye