 Hello and welcome to day 11 of advert of code in Haskell It's been a while I've been doing it now for 11 days like we're almost halfway through right? It's starting to get harder That's okay We have the power A pluribus unum no We're mostly doing it ourselves. Anyway, let's start with day 11. Oh my god monkeys Happy third advent. Well little Annie back at it With the tank Finally start making your way over realize your pack is much lighter than you remember Just then one of your items from your pack goes flying over that monkeys are playing keep away Put a monkey emoji and chat. It's too hard to find. Let me see monkey in the middle. Okay. Oh, wow It's a two which two or more players must pass the ball to one another by player in the middle attempts to intercept it It feels like you know exactly as a form of bullying. What the fuck? Wow. Anyway So we take some notes on the items these monkey currently has how worried about your life Well, I won't give my sensation basically where the blood first Just Good thing this is all remote. Anyway, okay seven monkeys Okay, that's it so proceed, thank you Okay, so they work on how worried we're about each other. Anyway, this is a bit much but I have to say Okay, then let's just put this into example and If I like some example Okay, three monkeys and we keep the example here now, let's parse a monkeys data monkey Equals and okay, it has starting Items is a list of emails. Oh operation is new equals old Times 19. Okay, then we let's just do that a Operation so sometimes it takes in It just takes in one Operation, let me get the input. I'm not worried about how are we gonna parse functions Let's get the actual input So it's all divisible by that's in the operation and then it's all new It would be probably be a lot faster A test, okay? Okay, throw to monkey and then throw to monkey and same here. It's all a test There's some condition Okay, so divisible by monkey to monkey. Okay Repeat to preq. I think it's read preq to P right to preq to Yeah, so where's the reach preq? Yeah, so it's read preq to S this Or is there a combinators? And then this is rp.live And then this is gonna be read preq. So how do we parse a monkey? Well first do first we read the screen then we skip space parse and int So we reads let's see how do we read it? We done this before right a read as Okay, it's case-paid read as to P Let's see how it goes because we don't Enable type application What is the problem here? gco, day 11, day 11 of HS and day 11 Why is it complaining about now? Okay, why doesn't it want to do string? Okay, and then skip spaces, right? Let's just do fine and monkey and then we do ratio now, let's just do this one Let's actually do lines We have my lines over it Let's do the chunks function from day two We do a lot of these chugging things because we're just gonna take the lines and then give it a couple of lines Chugs and then one monkey takes one two three four five seven lines Compilate it compiles now. Let's do read input Instance show Show is equal to Relative no parts. Okay. Let's say first a trace show here. I didn't save the file monkey zero. Okay, then Yes, good do monkey skip zero. Okay, and then I'm gonna get the monkey number and then we're gonna do chart Skip and then we're gonna say starting Okay, we're gonna say string starting Now we're gonna say Set by one. This is set by the chart comma so Let's call this here Now we're gonna print out the number and starting Okay, you got the starting on it. Oh, you're gonna skip spaces boom Okay operation new equals. Okay, so let's say here String Operation called a new equals skip spaces Okay, now we have to do this a person expression Okay, and then what are they probably the okay operators we use it's either times all times old or Okay, let's do it. And then we're gonna say parts expert and up is parts expert where expert equal to do so is it gonna say first a string old Okay, and then Up is gonna be a choice So we have two operations, it's either gonna be a Char star and we're gonna return multiplication or it's gonna be Char plus and we return Okay, and now we skip spaces again Now so cars of our Okay, so string start with all the skip spaces. Okay. Now we have a choice choice Raise equals a Choice it so either we get a string old and then we we return turn a function that says a Well, we always take in take it in old and returns a Up old old Okay, otherwise string Otherwise, it's a read so it's gonna be do A int we read the end read Add in and we need to do read as to P read as to P reads int and we return a Function old up old I hear Choices It's just choice. Okay. Now parse expert Rates and returns the operation Okay, so we parse the expression and They let's see where we're at that. Okay, it didn't work So we two string old now. Let's say a Trace show and let's say look into So we're passing expression. Okay, we said old Skip spaces then we get that. Yeah, okay now We parse the expression we skip spaces Okay, so we get that. Okay. Cool. See I like how we didn't Check it out and be like We just party skip spaces. Okay. Next we have a string test the V divisible divisible by skip spaces and Test div test div is gonna be a Let's have a test here to be parsed test. Now we say Okay, I let's actually make this into a Not parsed action parsed up. Let's just Pursing it's part of the same. Okay, it's gonna be string operation new equals skip spaces and then we have This is just Make it a bit cleaner And meaner Okay, parse up. That's like this parts test equals a string test call them divisible by skip spaces and Then we read the number And we just return and the operation return is And Mod Number Equal to zero. Okay This is how we say divisible by So we parse skip the basis of parsed test 2% number. Okay. Okay. Okay. Let's say it has A test is gonna be what we recall it. We said to call it test. Okay, and then Parts Let's print what we have now True if true. Okay problem again would do. Okay, then we say a bars cond Is gonna take in a stir don't do a string if and then let's say a Skip spaces and then string stir and then a String row To monkey test, this is gonna be Okay, let's just return the number. Okay, so skip the spaces if true then we do a parse con We need to keep spaces yeah cars con true Okay, and then skip the spaces Huh, and I think we did it and then we're gonna just return and Right, and it's complaining that a number Operation, okay, this one is gonna be operation Operation what is not what is missing here? Okay test true test false Let's say test true The test is not into it is actually into Booyah. Okay, we got monkey one two and three. All right No, I just want to see if we can Let's see if we also parse the input. All right We managed to parse the monkeys Hey, hey, we're the monkeys Monkey go monkey around Yes, it's because we are Okay Read monkey unlines a Where is it in the current trace? Okay, we managed to pass the monkey. Let's say now. What are we doing with these monkeys? Just pure computer science. We don't really care about what we're doing Just want to set our Monkeys up. Okay Three monkeys Each monkey has several attributes starting items. This your worry level for each one monkey is currently holding in the order They will be expected operation shows are your worry level changes as that monkey inspects an item Okay, test show how the monkey uses your worry level and decide where to throw an item next After each monkey inspect an item, but before it tests your worry level Your relief that the monkeys inspecting damaged item causes you to worry level to be divided by three And round it down to the nearest integer The monkeys takes turns inspecting and throwing items on a single monkeys turning the specs at all the items And this only one retirement order is listed Okay, monkey zero goes first and monkey one and so on each monkey has had one turn The process of each monkeys taking a single turns called around a monkey starts around with a white It's the kind of expecting that when there's time its turn comes around if a monkey is holding no items at the start of its turn its turn ends Okay, uh any little any is in the Christmas mood Okay, a monkey bite going item where levels divided by three two five hundred and one uh-huh 500 so it's not so it's a float Current worry level is not advisable by 23 anyway, we're level 500 it's round to monkey three Okay, um We have multiple pockets and we're like throwing From the pockets Okay, now let's then Do this I feel like we should have like We should have some We should have some buckets here. Uh starting items Let's have this to be an int map because we're gonna be updating it a bunch. Uh, no, we have to repaint in the list Okay, then so, uh monkey and turn Take some monkey and so, um What does it do? um, I'm gonna expect things And I always throw two other monkeys, right? Okay, it takes a monkey to a monkey Int map, okay a Monkey turn now, let's see monkey turn Okay, so, uh, we have the Let's first Do all the worry levels Okay, it equals so and so where Items equals starting so items prime equals and map operation Over a starting items. Okay. So first we do all the worry level uh Uh, the worry levels So it first do it and then we divide by three and then we check Okay, let me see Anyway, so operation shows that it's an operation test show after it's monkey inspects nine But before it has your worry level you release that the monkey's expecting to damage it because he will survive by number three I think that's just diff, right Uh, so I think it's just like this. It's monkey and then flip div a flip div three So these are the items and then And then we're gonna do a So it's not spam. I don't think it's bad. It's a partition Partition I think from google. Let's see google partition Yes Okay Import did it on list partition And then we're gonna partition based on the so it's so Tt and t file so test true and test test t test f equals partition Test Okay, so we partition it based on the test After we divide it by three And um So let's actually Keep it like this. So this is gonna be int map So these are gonna be things in air Okay In air we take a monkey Uh, and we just we could just actually When we initialize it we'll just put the Uh starting items for that monkey Uh a so let's just say in air I am dot bang We have starting items, but we are actually using them too much. Okay, so, uh import qualified Int map data dot int map as I am Import data dot int map Map as I am No We just get the int map And then in air, uh, and then you say number Okay, and the this one so we partition the test And we say a So we so we modify the impact by so modify I am dot modify Adjust, okay, adjust the value to specify the key when the key is on the under map is returned um update I think it's just adjust because it's always gonna have the An empty list for the or the starting items so I am dot modify and we're gonna add test t Uh, no, sorry, it's adjust Adjust So this is got the operation and then we say this is the True test let's call this True test false test And now so we want to add the to the true test Yeah, plus plus test f false test And finally we want to say I am Dot adjust Set it to the empty list Hey For the current monkey right because they've just processed Int map of a list of things and let's go to this Um, yeah a number Testy test f oh partition Then test Then we just do the flip the map in error. I am number Okay, this is a monkey turn Now We don't care, but let's say one turn After around one monkey's holding eye with these worry levels. Okay. Now, uh, so task one Uh Takes in a list monkeys So let's say task one equals a fold l Okay, a So this is gonna be a a monkey turn This is how fold l is right b a b yes monkey turn And the initial map Where okay, uh Initial map is so the initial map It's gonna be a map. Uh, so we take a monkey and we give it into a number comma starting items And we map that over the And so the initial map here is monkeys now Initial map and fold l and then Initial Initial map And the problem with the initial map is that it's not Okay, now this should be one turn. Okay, let's see read input example ask one print So 20 23 27 26 20 23 27 26 28 8 25 1 6 7 207 1 1 10 0 46 Okay, so around two after round three after round five Okay, let's say call this here. Let's just say here Turn is equal to um Takes an int map. So it takes a list of monkeys And takes an int map to int to int map to int turn is equal to uh fold l monkey turn Monkeys This is gonna be flip So this is one turn. Okay, uh, so if we say then uh iterate So let's call this Itcher so let's call it iterate And so let's say take one And then print iterate Turn and iterate needs an initial value, right? um Okay, so this is actually here's monkeys. So this is gonna be iterate a turn It's gonna be head of iterate A turn iterate turn keys And then Initial map. Yes. Okay, so let's see here task one Grand task one Is this turn two? Okay, let me see. This is a monkey And it's an int map is equal to fold l Then we're gonna say flip So this this one should be just turn turn turn monkeys Apply to initial map. Okay, so that and so the turn here is correct. Okay iterate turn monkeys initial map Print. Okay, I feel like this is the reverse ah This is the initial list Okay Make sense Okay, uh chasing all monkeys at once about we're gonna have to go Be able to control the monkeys monkey each time Each monkey inspects items over 20 rounds Okay, so then we just say a So Okay, so we say take 20 We might be out by one here Take 20. Okay, so rounds equals take 20 iterate monkeys initial Okay, and Now we are going to say map We're gonna map over the I am okay. I am So we're gonna say How do you map or an int map? Okay, it's a functor. Let's just plan say Per round equals I am f so it's gonna be f map length. So we're gonna say map f map length Round so let's just start with a two two rounds first and we're gonna say let's say this is going to be a int map int it's going to be a list of int maps int Per Okay, let's see what happens here. Now. Let's not take two. Well, okay. We can actually do that a Round okay, take 20. So we're just gonna look at the first two. Okay So this is this is how many a items monkey zero has four then two Monkey two has three items and monkey three has one item And then monkey three okay Now union now I'm gonna say something called union with oh Hey Let's just do that. Okay. So this is gonna be I am dot unions with Plus and this is gonna be Okay, now we're not gonna take two here. We're just gonna print task one Let's ask one 101 95 3 1 101 95 But because so they because they look at it They look at it like per round Okay, we're not quite there. We are there for monkey number zero But because we kind of because for monkey zero it starts in the beginning and then Okay, we need to do this again Um, so we can't do it just We need to figure it out. So we because we're counting how many times they check it So let's say we're adding the test here So it's gonna be monkey starting. So we're gonna just keep track of How many times people have expected in here and this one is gonna take an int map and it's not a list of It's a list of int comma In this is gonna be a Is it gonna be a c comma underscore a let me do c plus length D Where her items equals in Air number And we're gonna do second. Okay, and this is gonna be a oh wait Her items is gonna be first of this one and this is gonna be second Of this one Okay, and this is gonna be c plus I know so we actually need that. Okay. Yep. Sorry Her items and this is the the second and now we've looked how many we processed Let's say plus length curve items and then the new items that the monkey has is just you know, this Okay Is equal to L s right Is equal to a c comma l s plus plus l s prime Now let's go This could actually probably be a set but we don't need that add a Flip add test t flip add test f Do Okay, and what is the problem here, right this one actually should return Int comma and now we are and we're not gonna do this We are gonna say um Let's this is a list of In comma Let's say Okay, and this one takes an in comma now, let's take one round Take 20 words Okay, now this was gonna be the uh, we take the head of reverse head reverse round I am dot f map f map f s t So on the like the after 20 rounds, right? Okay, so we say so around We take the head this one, so we take f map first Okay Oh, we do not really need the other here in between this but it's all good in the hood Okay, the two most active monkeys. Okay, and then list of hints I am dot l m's Okay, this is the Level of monkey business. Oh, no This is the level of monkey business Okay, what is the level of monkey business for the input six four three two? Let's see Slow today. Oh, that's the right answer. All right Cask one done Hope all the work we put in a Okay, and now we're certainly not gonna keep the thing in memory, right? Let's see Uh, because we don't need we can just take and okay since he iterate Uh, no, I don't want to say And a to a to into two So a to into two So let's say What do we do? But what happens here? Okay, this is all int maps A you can still be an ink map, but these will be integers Integre Okay, then we don't say so reads and then starting items. This will be read at So this is actually I mean it doesn't matter for Let's go Could match type in the fact actually trigger into bull So right, okay Integre Now we can do all the monkeys on so I'm wondering if we can just Okay, get away. Can we get away with it? Probably not right? It's gonna be like one of those. It's super slow for doing it Then I away Monkey turn two Okay, and then we just don't divide by three Expect it. Uh, yeah, that's because this is integer. Does it still say it? These are all intercurses The monkeys are correct Chunks are correct Intent integers This is monkey turn one Oh, hey big alpha How are you doing today? We're seeing if we can get away with being lazy And just run it for a thousand rounds I think it should work, but I'm not convinced What is the problem? What is the problem rounds? Okay rounds is a list of int map int comma list of integers Now here I don't actually need that I don't actually need it F map first F map first F map first, okay Uh, let's see. What was the day eight? Part two, I forgot. Rounds is an int map integer. So this is gonna be an int map of int Okay, yes Let's do reverse And then we take the Head oh, yeah That was a bit We did it by transpose Transpose transpose transpose. No, we did it like by kind of dynamically. No, it's not almost dynamic. I think I think we almost had We could have made it dynamic But we kind of we did it the boring way But we could have been like kind of lazily evaluated like oh this one is the sum of all the other ones We we ended up not doing it. Okay. So what is the rounds here? Okay, and then to reverse and then to head Okay, so this should be int map of int comma list of integer Okay, then F map fst It should be a list of int Okay, and then we do this We reverse this work and we do the product What is the problem here? Okay Oh, well, this is still we're editing task one. Yeah, but we wanted to be editing task one. It was a bit We had to yeah, I mean it was it was shenanigans, right? We had to We had to make it work Okay Okay, this is how it is now Ask to Where turn Turn is going to be monkey turn two. Yeah, so monkey turn two Same but okay. We do for 20 turns Okay, let's see Ask one. So let's use the So the component numbers don't get that big but the resulting number gets quite big Okay, so we sort them and then we don't know we're not going to product like this We're gonna say integral now from integral and We're gonna go from int to ticker a map do I convert these two to Let's time it. Let's bump up the task and we're doing it for the example So Bump it up to 2001 this might take a while Okay, let's say not to ten thousand and one And it's all through Let's open another terminal and just say h tab Okay, the VM is just stuck that is Sad Which means that we need to actually do a bunch of stuff Which my the vsl should not be doing this bad, right? It should at least Do not correct, but it did okay. Let's go back to Maybe we should run it for some smaller values first, huh? But you know, this is what have we been asking for right? We've been wanting to We've been wanting to do more performance heavy stuff, right? Let me just check one thing before We have rounds it may be intended to take ten thousand one Uh Oh, okay. So now we're just kind of keeping every track of everything Which is a lot of Work And it doesn't work. So Let's think about it a bit Better Okay, so like this one, right? So if all this is advisable by 23 um It's never gonna it doesn't have to yeah So I want to see if I can like compute right like what is the result Of one round, right? Like how do you just how do you just? Okay Now we're like throwing one of the monkeys And then we're adding them to the list Okay, let's see the the crashed for ten thousand one, which was okay Let's see what 101 does how how bad is it? Okay, we don't have any history either Let's say here, uh ghc. Uh, let's see cd day 11 ghc o day 11 Day 11 dot hs and Compile it Okay for 101 it's not too bad. So can we like Could we somehow memoize it? j 101 A thousand one Is it already super bad then? And like how is it slow is just taking up all the memory or Because I feel like you know, it shouldn't lock everything up, right? That is for sure. Okay. Wow. We just Just consumes all the memory. Okay that day That's why it just crashes that bad Yeah, okay, so it's not really slow. It's just crashing And it's probably because we do this iterate thing, right? So let's not do iterate Let's write a f apply and takes an int and an a to a and an a a and returns an a now apply and zero Doesn't matter initial value equals initial value apply a and if apply and Diane and minus one f f of a So this is going to build up a bunch of funks Okay, let's see what if this is any better So instead of doing reverse of round head or reverse around we will just do apply and thousand one and it's a turn monkeys Initial map, let's see if this is any better It should be right because we don't actually have to keep the list We might need to make it strict though. Let's see here. It just eats up memory So fast damn for 21. It's a it's not giving me the right one for what was supposed to give for 20 All right, that's because it's monkey turn two monkey turn Yeah, okay. So but it still is we were correct in that it should we should apply it Okay Um, we have the initial these are these are not the this doesn't matter So but let's try and make this strict import that from data list Let's say now we have one monkey turn two The fold l prime should not have as many things in memory Hey, let's see if we can do like It's also like a lazy map, right? Let's do Let's make the map strict Okay, so now the map has been made And then we don't have as much Okay, we can actually just change this to An ideal map Can I see what happens now? Okay. Hey, now the map is strict. Can it go up to a thousand? Still eats a lot of memory Ring ring ring ring ring. Let's try and make it apply and strict Uh strictness Ask for a bank pattern A b b d b d b b b Patterns here. I think it's then becomes Bang maybe it's already gc 2021 probably not no Let's not try this dude. Let's try to do this dollar bang So, okay, so it's really only this, you know old times old here which a affects Makes the numbers huge, right? Uh, but multiplying a number by itself will never affect its divisibility Okay, so what I'm gonna just do is I'm just gonna say star and then If it's a Old then just return old Because I think in the input also We're multiplying old plus two plus five and then here we square it So I think maybe that's Not full Okay, but it so now we can get the number The numbers are a lot smaller. Okay, let's see Okay, so that that's really the problem here is that This is the problem is that these numbers become super small super big a So we want to Somehow address that right so apply and and apply and So let's just see if it handles this Yeah, see We could do it If not for this old times old operation Beepity beep beep beep But how do we so how do we handle so eight times a mod b so there's some like he here, right? It's a bit funny, right because it should not affect its divisibility Because then there of course, we you know, we add numbers and stuff like that later It's a how do we how do we handle that specifically want to do So I feel that's also what's happening, right? Like it's doing fine until it hits these huge numbers and then it's Then it starts slowing down real fast, right? Anyone have any ideas feel like this is this is now it's hard, right? We saw that right? I think it's not really the data structures. We're using right. It's really the It's not like a Haskell part that's slow. It's just that the This testing and multiplication Is what's Slowing it down But even if I have if I have if I have monkey turn here It should still be not so slow If we keep dividing by three No, maybe not little any you've been watching so many of these Where you don't learning anything Okay, and Right. So monkey turn is so it's also bad for monkey turn If we always multiply them together and then um, maybe I need to make the uh This one straight Let's see. How does it look after? A hundred operations Could I like periodically like Like clean it up. These are some big nums So it would be really nice if I could like do this modulus something, right? Like, you know, can I multiply together all of the numbers? I should be able to do that. I think okay, so if I take all the The tests Let's make the test actually not like this. Let's just make the test be number Number okay, so we put it as a number And then the test is a is an integer okay, um Divisible by reads that integer and return number. Okay, well, then we just do return like this Okay, now instead of doing partition test we do a partition A to test is going to be so it's going to be and test a test mod No, it's going to be n mod test Equal zero Okay, a Now and we're going to see the same here test Zero equals dot mod test. Okay, it's going to be like this I don't I don't think it works. We cannot just do modulus a Because like the pluses are there as well, but let's see a The test mod test to monkeys. Okay Now, let's print. Let's forget this here. Okay, so All test equals product Our product map test monkeys That's so map test a monkeys monkey. It's called a test right here. And what is the problem like this? By and turn monkeys in patent integers. So all tests is an integer now What I am going to do is a Modulo It's going to be take it's going to take an int comma list of integers And it's going to return int comma list of integers Modulo a Do mod a Do do mod. Okay. Do mod I comma ends is equal to map mod tests a NS Let's turn this into an int map in comm weniger to a map A and this is just f map and now let's call this So and then we just into integer into Blabla blablabla blablabla Okay, a all tests. Now I'm gonna say f map do mod Those are very good so this is the idea right we just keep it within the modulus of all of them i feel like this is chinese remainder theory something like that but i don't know let's call let's see here 21 now let's apply this 20 times and let's call it for monkey turn and let's see what it does maybe it doesn't matter for monkey turn 10105 now i want to see for monkey turn 2 and what does it say for monkey turn 2 after around 20 gd day 11 gc o day 11 day 11 hs and day 11 so 10105 2 305 so 99 97 803 99 97 803 okay what does it say after a thousand and can we even do a thousand five two zero four four seven nine two five two zero four five four seven nine two one nine nine five one nine two oh no nine five one two okay okay let's uh let's keep going right um what about does it still work oh no okay let's just go to 10 000 five two one six six uh four two zero one three huh so it does work oh my god okay uh yes so what did we do we did something called chinese remainder theorem okay and so if you're taking the modulus of a bunch of numbers and you can this is isomorphic to a ring blah blah okay so what happens yeah so we're doing like something like case of two okay but the idea then is right so instead of we can because we're all only checking for divisibility and that's the only thing that matters actually actual numbers don't actually matter uh we can just take the modulus every time and keep them within the ring because you know if we add to it and we multiply it we're just kind of figuring out new steps in the ring but uh yes okay so i'm gonna do it for the input now but this is the number right for the example two seven one three three one oh one fifty eight now it's gonna it's gonna be slightly slower for the input because it's seven numbers but not too slow you see how we did that though we did um we used the math let's see boom i guess that math degree wasn't for nothing anyway this was a hard episode and but i might not have a bother to solve this as i didn't know this math trick and i mean i didn't i didn't i wouldn't say i knew it but i'm aware of things tricks like this so that's why you you can think of it let's just give it a go if it hadn't worked we would have been doing something else but uh yeah but the idea is that so divisibility is only affected by like uh so yeah so you so you just multiply all the checks the divisor checks that you're doing together um and then yeah because and then if you do modulus that like yeah if you go above that right you're still like the divisibility will still only depend on so the visibility will only depend on where you are in the range of those numbers right uh how to do this let me explain it a bit so here's three so three let's say three times five let me let me write something here uh okay so we're so we're gonna check if something is divisible by three and if it's divisible by five all right so let's write it out so we have zero one two three four five six seven eight nine ten eleven twelve thirteen eleven thirteen okay we don't actually okay so and the check so this one is divisible by three and five and three and five three and five and three and three and three i feel like there's a bigger gap okay three and five and three okay now let's look at 16 that so that that's kind of back to so this is gonna be we actually don't have 15 here uh so it's gonna be x y okay now 60 so yeah so the idea is right if you're just checking for divisibility between these two numbers that this pattern here will repeat it so so let's let's write it out again like 16 okay let's actually have some numbers here you should study math kids okay a three a five oh my god a six a okay and like this and then 12 was there and 15 so 16 17 18 19 20 21 22 3 24 25 26 27 28 29 30 31 okay so let's look at it so not divisible not divisible 18 is divisible by three right uh maybe i'm screwing up here x a y x a 23 24 24 is divisible by x and y okay sorry it's 15 then 16 17 18 19 21 22 23 24 25 26 27 yeah that's divisible by three 28 29 30 oh and then this is x y again sorry x y right okay and the problem is here that 15 should not really be in here okay so this one so zero is divisible by both okay this is why it doesn't look right so zero is divisible by both okay now 15 should be here and x y so divisible by both right and i think this is called the chinese remainder theorem right so look take a look see the pattern repeats itself uh and this is the idea right so the pattern will always be the same so you just multiply all of them and then you can just keep it within this range and it forms a ring right so this is all number theory okay people like ramanujan shout out to my main indian mathematician they're all about this right so and this is why cryptography works right anyway yeah and this will repeat itself again and again right i don't know i'm gonna explain it but so take a look at chinese remainder theorem so those are right yeah okay maybe it's not the chinese remainder theorem but it is yes uh oh no okay i think this is the opposite okay chinese remainder theorem is something else so you see pretty lovely i did a lot of verbatim copies in which my nose a bound on the size of the result by several similar so okay so it's actually rings or something anyway so this is the idea right and the trick is that these are all prime numbers yeah i should mention that this doesn't work if these are not prime numbers uh yeah that's important anyway the pattern repeats okay let me put this right here straight up the pattern repeats oh my god so we can do it be a modulo and remain within a ring and what is a principle ideal yeah this is like the passive part of math that uh so i failed the test this is like algebra one in math at the university so i had so i failed it because i wasn't paying attention in class and so i had to study it again next year to get the math to get the uh to do the test right so this is why i think i remember this clearly all right but anyway math state 12 and day 11 uh get at day 11.hs input example get status get commit um day 11 get push okay that's it for today um just remember this trick and do it in your language of choice but of course classical is a language of choice yeah i was worried that we're like oh no it's lazy that's going to fail no no it was just math anyway i'm gonna do this again tomorrow same time six o'clock and i hope you tune in maybe there'll be some more math tricks anyway thanks for today and uh yeah hope to see you tomorrow all right bye