 Hello all, welcome to today's stream. These dreams have been very long, so We're gonna do a short one today. I'm just going to task one and if it takes more than like an hour I'm just gonna feel it Sorry about that, but can't keep doing this Extremely long stream. So you have Christmas stuff to do. All right Let's get cracking I'm just gonna focus now No chatting. No nothing. Okay. So the elves have a file and it's a code encrypted And that's on the mix each number for back with the file a number of position equal to the value of the number being moved The list is circular so moving number of one end of the list wraps back around to the other end as if the ends were connected For example, I'm going one sequence Like one four five six seven eight nine and the one moves one position forward Then this file here is gonna be extremely long. Yeah, this did we got 5,000 numbers encrypted file an example. Ah, I gave the wrong name. So that's okay Now, let's get cracking read input File path I own this event input equals map Lines read input Exit a 20 You don't need just a maximum. I gotta save this Okay, then the growth current can be found by looking at the thousand two thousand and three thousand numbers After the value zero wrapping on the list as necessary In the example above the thousands number after zero is four, then the three minus three and the three thousand is two Okay, then with them two minus two and the polygon likes minus two moves to position backwards wrapping around Okay, so We're just gonna do modular arithmetic. I guess Let's just calculate it like that. Uh, so these are going to be you're going to do some modules Okay, and so new pause we're going to take the int and the the value The index and the value we're going to return the new pause new pause int also the length of the list L a and the int and the v Is equal to int plus v Let me see. How are negative numbers in this school? uh minus two Mod, yeah, so we go one The two mod three is two. Uh minus two mod three Is one Okay, now let's uh map this over the read input Ask one. Okay, so it's going to be equal to map zipped with new pause length length of the front of the list So it's not going to work because like the the new positions will affect The old positions. Okay, let's zip first together the Okay, and then I'm gonna So let's do your mix Make a list Uh, but it might modify the positions of those that came before Let's just brute forces. I don't know. I'm not in a good mood. Okay, and then I'm gonna have another that's just a list of list of transpositions And then let's go for uh band trans Roses or ugly Okay That's one prime one prime. So if I have something here, I have the oric Dex and I have the value Where curl in is equal to Okay, it's gonna be okay. We have the current index The value and how much should the current index change We let's see here a new in It goes um Int plus v and plus v now let's check So all the ones that are We just map, right? Okay, up the Upd is equal to um E i is equal to So if the i is equal to new in no Current Okay, let's see The one goes from one goes to so the Your eye Update i If i is less than or equal to First of all if i is a But we're let's check see if we're moving Forwards or backwards Let's just see upd is it there's a loop here Let's see me if new and new and Is greater than New and is greater than less than Current is greater than equal to new in And in this listen Current so it's between there if we move it forward then we do the other way. Okay Yeah, we gotta get these conditions right We'll figure that out Let's just see what happens with one of them. Okay zero state unchanged int is equal to The zero became one One became two but i want want to become minus one now, let's see Do i mix? And okay, so we're gonna do or again map is equal to Dot from list of the swap function Do i am dot asox We do map swap and i from list again Let's Do the transpose isn't here And we're taking the Okay, so two one minus three three minus two zero four This is after the first one And then two moves between Minus three and three Let's take two here One minus three two three minus two now. Let's see if it works for the Negative one. Okay, so i think i should always do mod mod So one two three minus two zero minus three four. Now let's take the fourth one We have a one two three minus three two minus three But one minus three two three Minus two zero four We have minus three moves between minus two and four. I went one too far it seems I think i need to do Mass import util trace sure trace Let's do here or if i comma v I try to apply all the methods in that. Yes, exactly The first zero becomes one and then one becomes two Okay, then it one becomes two. Let's look at that. Okay, so Up the end. Okay, so If the Current is less than the new End then Then everything Then there is another looking at some current value We only change those that are between the current index And the new index. Okay, let's Right, so the other ones will not actually change. Let's see here to Change case cur and Less than new in is equal to End up to new in one to one. Let me see one to one So instead of mapping over all the indices we're all only going to map over these Okay, actually, I don't want to do mod over the list So then at the end we'll just kind of take the negative numbers and we'll just um Renormalize them, right? These are the ones we have to change. We're gonna say here that we're not gonna Okay, we cannot like map over partial. Okay, so this to change doesn't actually matter Let's just not go anything. I'm gonna map the update or I'm gonna map up the transposes update index okay, so Let's see. Let's do this case cur and okay, so If We're just not gonna do anything in that case. Let me have two cases here cur and Less than new in and we have the case where Is larger than Cur and up the equals Of the current index is less than the new index then Then if index is bigger than So first of all, let's just do Up to end case End equals cur and equals new in the simple one A current because of the end is a larger than cur end And in this lesson equal to New end Then I want to bump it down by one. Okay now I've in this So all the other ones The other ones they put right the get so go zero one two Got the other ones like three will still be three, right? So this one becomes one Let's see one two minus three three minus two zero four comes to one Let's see three minus two zero four, right? Otherwise it just Okay, so current is And is new and so then we do if and is bigger than new in And it is less than the current And we want to bump it up. This is actually this case This is after two, right? So two on here and then one minus three two Three minus two zero four, right? I think this just works. Let me see here Non-exhaustive pattern to the function update, but it goes minus two And I don't need to do this one two three minus two minus One is off by one one two three Minus two minus three zero four One two three minus two minus three zero four What happens if we just do the whole thing? Okay, now we drop those Interesting one two minus two One two minus two minus three So this is because two is going to five, right? One that's currently at number one One that's currently at number one Who's two five zero one two three four? How does it move? to four um Because it goes minus one minus two minus minus three Let's see One two four minus three zero three minus two Okay, let's just do it the good old fashioned way And you end a end equals Kerr End plus b equals if new int-cand is larger than equal to length of the list Then you then new int-cand Mod else If new int-cand is less than zero Mod Minus one for some reason else Hello, Bob Ross RTX. How are you doing? Take one Okay, let's take two Let's take three one two three minus two minus three zero four Just take four one two minus two minus three zero four We take five one two minus two minus three zero three four one two minus two minus two moves between four and one one two minus two minus three zero three four right here minus two Two go at the end Okay, then zero goes to one This will be the result So one moves between two three one one, yeah Two moves between minus three and three, yeah minus three moves between minus two and zero which is five one two three four five six one zero one two three four five um I've never understood Haskell I mean, it's not that difficult. This is a bit different. You just need to You need to Know what you're looking at. I think the minus three goes What's that one? Minus three moves between minus two and zero Maybe if I one index this whole thing Okay, so minus three one that one moves between two and minus three Now minus three is at two and then two moves between minus three and three And I was saying minus three is at two But minus three is actually at one There's something wrong with these indexes here Very sure Because I'm doing here Okay, one two minus three and three one two minus three three minus two zero four Because two one minus three three minus two zero four One minus three two three minus two Now I should go So there's nothing wrong with that Anyway, okay, so It's two one two one three minus two two So just one goes to one is going to one two is going to three Three has gone to two Yeah, so okay three is at two. Yeah, yeah And then it goes one two three minus two Because it's currently at two so we go It's probably because I'm doing this This is all a lot easier to wrap around than this inside ship. It's just zero Otherwise the modulus is quite one two minus three One two three four five six Now minus Three started off at Two and is now ending up at five But minus three Should go minus one minus two Minus three minus two minus three And zero so it seems to go one more and it should then Okay, I'll just do like this The value is less than zero one two three minus two one three zero four One two minus two minus three one two minus two minus three zero three four And then we can one two minus three zero three four minus two Okay, and then we get one two And then the zero doesn't move And then we're looking at the four Okay Okay, then if a new end And is larger than we will do a link Then then we just add one right one two minus three four zero three minus two Okay We did the mix Then we have the like the final transitions Now let's see here This transposes end Okay Now I'm interested in the position of zero. Let's see here Okay, so now the position of zero Orx zero equals find Index or data dot list Point index now type of pointing text is Okay, you actually want element index here. Okay, and we're gonna do Just orx zero equals Okay, now Just final zero uh index Equals transposes end. Now, this is actually a Final trans where did zero end up here? zero one two Uh zero started off at six and now six ends up at five. Why is it saying four? zero zero one two Okay, that ends up at four Okay, then K is equal to uh final zero i plus 5,000 g 21 One k two k equals final zero Plus two Mod uh, so this is here. I've swapped the ones Uh three k okay, and let me actually just do it the other way So let me get the uh nums map and we're gonna do Transposes end transposes end I am dot bang Plus i actually all of this Mod to Let's print the nums here Six two and one, uh, and it's the original one It's one at that six which is four It's a one at two which is minus three and then it's a one at One which is two Okay, so I'm going to actually say here Lee bang bang four minus three and two with the this is the sum of the nums three Okay, now let's see how this works on the input Three's show Not as it do for the input. I did not do a lot of efficiency. One might actually be up. Okay Five eight six five It's not the right answer man. I'm doing something wrong Okay, we didn't get it in our first try. There's something wrong with this All these ifs here, but I set myself a time control today, so I'm not going to do anything more And Let me see if I'll finish this later, but yeah Um, let's see. I mean it did work on the it worked on the Maybe this is supposed to be just bigger than It said it was too low. Here we get the same This one doesn't even work for the example Of course. Yeah, I only do a check for when it's equal There's nothing wrong with the checks Uh, I don't know why but I think this approach could work right just do the Just like keep updating the indexes, right? So don't be moving things around in an array Uh, certainly not like you know the buffer or whatever just keep Just keep updating them. But you know, I would have thought that would work But this is very confusing this Sometimes we add one sometimes we decrease by one. I'm not quite sure What that all is about I think the problem comes up when the when it wraps around here Um, okay, I'm not gonna do more today. Uh, let me just leave it like this It's this It at 8 20 You may damn Partial day 20 Okay, thank you for tuning in And Yeah, I'll I'll get back to these one day and make it work I don't know. It's also like I don't feel like this is super interesting And I'm also always getting it wrong. And this is just a lot of these Specific cases that I don't like There's not a beautiful solution here. I feel anyway Thank you for today and uh, hope to see you again tomorrow. It's probably be the last day because Yeah, this is a lot of Christmas stuff happening. All right. Thanks a lot