 All right, welcome to the stream hope It's okay for everyone and we're doing it a bit early today because I Have a meeting At nine o'clock, so I'm hoping to get be done by then. I Think we'll give this two and a half hours or so Anyway, let's get started so Um It doesn't look good in the sense that not a lot of people have finished First part and not a lot of people have finished the second part. So maybe you'll be lucky. Maybe we'll be there. Hi little Lenny Welcome to the stream and let's see what day 12 Is all about Wait, I thought you were there. So the horse brings Not spring Not spring lava shortage. Oh, no This will be good to nice land we'll prove day 12 indeed Let's say Many of the springs have fallen to disrepair The condition records of which springs are damaged are also. I know in the giant field. Just as I said springs are engine into rows For each rule the condition record shows every spring and whether it is operational or damaged This is the part of the condition records that is itself damaged for some spring it is simply unknown Well, it brings operational damage. However, the engineer has produced the condition records also duplicated some of this information and format After that list of springs for a given role the size of each contiguous group of damaged springs Is listed in the order? Those groups appear in the row. This list is always good. That's why we don't spring and each number is the entire size Let's continue this group So start forward never without before never to do Okay, how the condition records Partially damaged some of the springs finish actually known for example Equipped with this information. It is your job to figure out how many different arrangements of operational and broken springs fit the given criteria in each row and In the first line there is exactly one way to separate several groups of one one three broken springs Can appear in that row? First three springs must be broken Must be broken then operational then broken Making the whole row. Okay, second line on each thing will be a total of Okay Last line actually consists of with ten different arrangements Because the first number is three second is to backwards First second question mark must be not How are the rain runner panels spring conditions and mentioned rays? Let's see what is happening now All right This is a day of stochastic indeed Santa Claus is are coming to town in Iceland. I Got a apple today, not bad Nandi got Icelandic chocolate, we'll see what gillagood will bring Okay One arrangement for one one four ten, okay So it's definitely doable per row. So let's just copy this as the example and Let's copy back the split-on function. I Don't think we use it here. Maybe we use it day nine. I'm not having like an immediate idea how to do this I mean, there's just one way to kind of generate things and then just checking But oh my god Seems like that would be very bad but At least we can try for the example and see, you know Me where Okay, we got the split-on function here. Okay, let's say language GT-2021 R's example We are going to get so it's really each row so we're not gonna Not gonna generate the We're just gonna have the contiguous blocks, right? Let's say String Let's just start with, you know, because there's a list of a string comma List of ints, okay parts, example, equal parts Map parts row where parts row Str equals a Where okay, so we're gonna split-on we're gonna have the str st and the nums We're gonna split-on the space split-on space And then we're gonna just return st and we're gonna return read at List of ints Um, we're gonna just add some parentheses around it the been hacking but It should work main equal to read file example Into print a parts example lines PGO day 12 day 12.hs and time Ah Because it's only gonna be two strings. It's not actually not like a pair creator.readno parts and let's do create show Import the world.trace What are different parts? Okay, so split-on does discard the initial number. Okay, so we got the Um, so we got the thing Now let's see What we do now, um So solve row string list of ints Let's see, uh solve row of empty is equal to one okay There's no more Numbers and we're just doing one solve row Okay, if we have a question mark At the start and we have a one here as This is just equal to so then we just do the dot Uh, let's see That is just equal to solve row Uh drop one Actually, yeah, because the next one is either equals um solve row rs rn okay solve row This should solve the first row. Okay, so we're just gonna say print I mean it's gonna crash for the second one, but that's okay Mm-hmm Let's see. Uh, we're just gonna drop the periods, right? dot rs rn solve row, um rs comma n rn case, uh, so we're gonna say, um all equal to this Uh, so first we're gonna H is equal to let's say, uh H rest is equal to take No, let's put it at n rs and all equal to This H is equal to solve row um rest All right. Okay. I think this solves the first one at least because that one really only has one interpretation Let's see Let's see what we can do here um We always reduce the rn um So if there is an rn Let's see Okay Why does it return? One comma one comma three. Ah, it's just because I I'm doing this Right, and I need to actually map and print So first one is solved And the second is solved So I got the uh because it might be Right, so the two question marks might be different feelings Maybe it's just easier to replace and just generate all the options That's gonna be difficult though. Let's get the input actually We hope that it's gonna be That is a lot of input So then anyway, we should just generate all the solutions and just check them. That's uh Let's write that. Okay, so that's gonna say um So let's just say a Check and now let's go back here Check we write this so we're gonna say, um We're gonna take in a string and we're gonna generate this list of ints, right? So check, um mt is equal to empty check Axis is equal to uh Span Let's see Where um So this is gonna be hashes and Hs and this is gonna be the rest You go to span equal Also, specifically doing this like with strings is gonna be bad, right? So let's not do that. Let's do uh powers example It's gonna be a list of pool Okay map Uh, it's gonna be not pool It's gonna be um Yeah, let's just call it a list It's gonna be uh data data Intree is equal to Uh dot hash unknown Where and you show more it can be a list of entry Okay, and to entry Start to entry Ash equals ash To entry Equals unknown. Now, let's uh Just check this again Oh, no, no, no, no dot Let's uh Not do the example just yet. Just to the check Okay, so now we're gonna say a check and arrange Of a list of entries to a list of ends is okay, so hs is gonna be span and Is equal to hash of x's and then it's gonna be Length hs Drop while Equal to dot Rest All right, and then we're gonna do now. Let's uh, let's map You meant dot first On these examples And let's see we're getting the right ones one one three one three one six Four one one one six five. Okay, and uh, we just have the so you were Access prime is able to do this And we just have the issue here that let's see If null hs and x's prime else um Link hs called access prime Okay, so now we've generated all of them for the check Let me say the Where was the check? Oh here One one three one one three one three one six Four one one one six five three two one Okay, so now we're gonna generate the List of options gonna be crazy. Okay options Takes a list of entries In terms of list of entries. Okay options and So if you have the if you have a dot options of empty is empty options of dot Something is equal to map dot options hash x's is equal to map map hash options x's options and unknown however x's is equal to um So then we're going to say Where rest is equal to Options x's and we're just going to say um Dot rest hash rest We'll just generate a list of twos Okay, this is going to be super It's going to blow up, but Thanks to laziness is might might not be that bad Let's just say park one is equal to strain to um Let's just make a string to Park one simple Part one as simple Is equal to stir. Okay, so let me say where um Let's just make it do one thing at a time Um map parts example Map parts example map Okay And let's just say where uh entries check Is equal to parts example Stir Let's just see if this compiles of it like there's a compilation Error somewhere. Okay, there's no error Now we are going to do very crazy thing Options and Options Entries filter Let's say filter equals check dot arrangement dollar and then um Links So laziness might actually just make this work immediately for us. Let's see map Okay, and let me see Press show ID Okay There's unknown unknown unknown So it's one one three at least let's let's focus on this first one Okay, and now let's Okay, I got Right It's because I'm always mapping and then I just end up with the empty list Um, so they should actually be like this Okay, I got one there Now let's not trace anything and Let's see how long it takes For all these options one four one one four ten Uh, let's say one four one one four ten Okay, and the sum of this print dot sum is indeed 21 Let's see. I don't think maybe it will work for the input. I think it might work Okay, it worked. Hello, Yash. Hello Uh, we're doing part We're doing day 12. We just did part one. I think Boom part one done Using the extremely naive way of just generating all the options um Which is uh That's okay. At least we did part one Um, I will fold it up To unfold around each one replace list of spring conditions five copies of itself Oh Okay, that's kind of crazy This will not work with our approach. I think That's uh Let's just do the unfolding manually Unfold String to Our example Okay, um part one simple Part two simple is of course just um Entries prime Check prime A Check is equal to concat Replicate five Check Prime and uh entries Enteries prime Let's see how long it takes Just for the example How are you Yash Vallo? Nice of you to join the stream We are doing Day 12 We finished part one with our Extremely naive solution Of course a trick here is that we would like to Now just generating all of them and then we we are We're just ignoring the information, right? We could probably memoize Right You say that like, you know, if you have a If you have a block of three question marks Yeah for the For the uh, it's not even finishing for the example, right? And let's see Might also be eating up all my memory. That would not be good. Let's cancel this Yes, exactly Let's see Okay, that didn't work So we need to be smarter about this. I like the fact that number one worked though. That was kind of nice We need to Replace the list of spring conditions with five copies of itself Separated by question work Okay Does not even just This one it's going to be question marks as well Hmm How do we deal with this? I feel like if we solve the beginning of the string We can kind of take it by group Let's see Let's do that for the example first, right? Uh, or for the part one so, um So this is actually concat But let let me just make sure to generate this correctly. Um, and then I'm going to do, um Interest spurs with this room data that list, okay Then we have the um, we have the Checked in address correct. Okay. So, um, Let's see If I have the one there What are the possible lists? I could generate Let me see Instead of doing the map, let's just do map M Instead of taking this out, let's just see how far it is getting actually Just not compiling it even That's not good Okay, it does find the first one quite fast But then it's doing 16,384 arrangements That's more than the entire, um That's more than the entire input So the problem is I'm not really getting any good ideas here I don't know how to like How to proceed, right? Maybe we can kind of recurse Somehow, um Let's tie these together So if I'm generating If I'm generating one If I'm if I'm looking at one Let's uh, look at this way. Okay Part one Part one Do not simple anymore First of all, we can drop while We can drop while it starts Okay, because dots don't matter In the beginning, so until we reach a question mark or a Go Dot Cs equals Go R-S-C-S Check Huh, there's not a dot right here until we get a Do we get a dot? We just um Go Which it's going to return that to just see what happens We're not doing the input anymore So we always have an unknown Or a hash in the beginning Okay, now let's um How's it like this? span Not equal dot a Monk comma h's And h's REST Equals, okay, and And then we're just going to say immediately, right REST prime is equal to Drop while dot REST Okay, we have on k and h's and we have Cs and we have um REST prime So then we get three unknowns At least one dot Then we can um So how many objects can this be? Hmm So I just kind of want to just do this for all of them Okay, just separate them into the groups So Let's not do the check. Let's just separate them into some groups Go entries We're not looking at the entries the Cs is yet Go Drop while Okay, and this is actually not gonna we're gonna have it like this we're gonna have it like Go REST prime Except of course and go event list Okay, so this is two groups And there's some number of dots between them, okay, and Let's see what we can do here I'm gonna put an alarm by the way So don't miss my meeting and let's see Alarm scroll, I have so many alarms And I'm gonna stop 10 to 9 At the latest, okay, so here we have um the groups separated by dots And we're actually gonna say Just go Just so we see what we're dealing with let's close this window So the thing is now I know So I want to say that so if I if I know if I know all of them So I can kind of I can tell that this hash group here is this three here, right? Hmm And I know that these hash is here one one are the I don't know exactly. I know that These are both um We're definitely out of something here. I think Let me do this for the input And just on like, you know, take 10 10 lines of the input I need to do it for all of the input Which I want to see if it does any help in like going backwards and removing Like would work in for the example, right? No, it's pretty much Doesn't really help Let's see and This is gonna be some combo combinatorics, right? Like for this one, right? It's it's it's gonna be Exactly two ways But I can make one of these be Um, let's see Let's write the selection one, right? We don't actually need to generate that we just need to Yeah, I don't know how to do this I think I'm gonna let me stare at it a bit longer And then we can see what happens Maybe I should not split on dots. I'm gonna be splitting on hashes Let's see that I'm just splitting on too much, I think Let's see. What does this split on function do? Is the split on keep Which instead of Just like this, um, and we're gonna say, um Off and it's empty We just do our Empty if it got something So We're gonna be doing R. Yeah, so Let us So split on keep We'll split on Keep Four one one is Split on keep is not working either Let's go back to splitting on the dots Hashes, I mean So I know between all these groups there is a dot And I know that if it says one one, there's at least one dot in between, right? How does he input look? I'm using One, five, two, five, three Six, ten It's never any huge number actually It's always less than 10 There's one 10, 11 Most of them are one actually Let's see, um Select Let's see if I had just had one Unknown Maybe if I have a n and An n is not equal to one Now let me see you also I have one unknown and I will one Is equal to Just With just the hash And the rest And if I have um If I have the case that I have ease And I have n Yes Is Then I have just Replicate And Hash And this So these are only one options Welcome if you're just tuning in I'm working on Day 12 part 2 And it's proving rather difficult Specifically because I have Then no idea what I'm doing Is a special case for two Is it going to be either hash Dot or Let's say Select We have two unknowns Unknown And we have one in the front Why I should learn haskell as my first language It teaches you a lot How to model data flow I think I really like it, um Might not be like the most profitable way to go about it You should probably learn python Or something because this is just a lot more material Out there on python But haskell will teach you a lot Right so It's got that going for it Which is nice I don't know how to I'm trying to I'm having a hard time modeling this It's first of all we're super nice if I could just see the threes there Um Maybe I can like pre-process it right By saying, you know, there's only one possible solution Um We can pre-fill in that solution Let's do this More efficiently actually Span Move dots And this is going to be a map I don't know if this is any quicker Could be Um Doesn't like it though here Let me see Did this make the Get any quicker No, it's still uh Still four seconds Doesn't help without Little quicker without optimizations But it's not like ah it's super fast now Maybe I can kind of generate the options and Instead of generating options and checking I can kind of use the effect of the increase Let's do that entry Okay, uh probably doesn't make sense to do this in this way but let's see And now for the dots We definitely just take a while Mm-hmm So I just want to take the um So if I'm going down the Dots path Then I just take uh dots until I can't Now let's say here, um This should be rest, right? Uh I should have it the other way around Entry and we have a Cs So what I'm actually going to do is um If Cs is empty and I have axis I want to see a case all So then the rest of them all have to be dot If all dot axis Then axis else Otherwise, I don't want So then we kind of bail out early if we have the checks are empty options with check Okay, and if we have We have any here About this is empty. Then it's we're just going to return empty because then We're missing some hashes Okay, then we take all the dots until we don't have any dots anymore So then we can assume that the previous One we hit was not a dot Okay, so then we write that case. So say options we check ccs The axis is An axis and we say Okay, so now we are gonna so the previous one was dot So now we're gonna say non dots rest span not equal to Dot Axis, okay Is equal to so case let's see now if and So if we took uh until we found and didn't find a dot and we if So okay, so if C is equal to the length and d right then We just it all has to be hashes map Replicate see Tash onto Options with check Cs rest Let's just do here else error show ccs and Exes No, that's right here Sort of this let's see Options with check Check oh no no no no no dot dot dot hash Hash, okay, we're hitting it right away Let's see if we're hitting a hash we hit a Hash so if we hit a hash then Um, and then the the next c have to be Let's just like that um Then we just to Rest is drop C minus one Axis Because then the preceding one was a dot until the next c minus one has to be hash also because we're in a hash group Okay Options with check Cs Rest Okay, now we know that we're in the case and we have unknown We have axis let's see In the here Actually, we have this axis at We can drop C here. Okay, let's see And now we're in this case the select case again except we're looking at the case And because we have these empty lists, we've kind of already filtered out a bunch of Impossible cases Already So one option here is to to make this unknown into a hash So we would have And we would do if we make this unknown into a hash we have to have c hashes So then we do a map Replicate c hash where's C hash is equal to replicate c hash Uh, let's see we map C hash C hash and then so we can so we can either We can make it into a dot um Go Okay, uh r s let's see do that so we can make it into a dot And if we make it into a dot we just do uh Let's options with check ccs r s These are the options if we make it into a dot or we make it into a Hash and then we need to make c hashes And then we are saying options with check c s um and actually Drop drop scene where I was one of us Okay, so now it's saying Hash hash dot These are the options So for the first one it's giving very strange stuff So it's saying I just see what it does for the first one Okay, we're supposed to put c's and we don't get any c's and it's empty Now we can do that. We're doing the dots Okay, and we if we see the hash then we say, um It's actually say Hashes uh rest Is equal to span is equal equal to hash Alexis and then we're just gonna check here If length hash is Is equal to c then else Let's see here. Um And the rest Where's axis? Let me see just see ccs Okay, then I'm looking at one and three and it's not one. So then it's okay Um I think I have to do map uh We drop c minus two actually here Because then the next one can't be a dodge Okay, let's see Okay, let's say take it back here. Um error axis Okay, so I'm looking at an unknown Maybe something's wrong with my Like the empty product thing Okay, so I'm looking at unknown here Let me see Axis Axis, uh, let's see b a x Axis prime is gonna be Just do s ps It's gonna be split at c Axis So, uh, if I can split at c axis Now let's see here So case bx up If this is hash Then we are in in Then we are ah if this is hash Then we just want to do So then this unknown has to be a dot Because otherwise it would be going over so let me do a map dot over Options with check a ccs Uh rs Now if if it's a dot Then we map Where c hash equal replicate c hash e hash Then we will c hash And then we don't look at the c but we are just taking the We're taking the bs bs Now if it's an Unknown Then we have two options Mm-hmm. Okay. First we have to actually check If If not any equals dot In is Else Let me see if any If any is dot in is Then we're in an impossible case Else They're all either unknowns or dots So then we check If we are if we have to make this into a We have to make this into a hash or dot But if we don't Then we can either make it into a dot Map dot Let's say is dot The is dot case is this case Is hash is this case? Oh, sorry. So this is the is dot case. All right Uh, let's just see here Is dot Let Make dot equal to this make Not make it hash is equal to this In so if we have to make it a dot We make it a dot if we have to make it a hash We make it a hash if We have the option to choose We simply say Map dot Then we can choose both. Okay Make dot comma make Mesh oh, okay, we can actually We have we have to concatenate these Okay, and Now let me trace a bunch of stuff here. Uh, let's see ASBSC Maxis All right So now I'm looking at the unknown Let's see Trace show Trace show Has to be Has to be dot Trace show Has to be hash Make hash make hash Trace show Both Possible Let's make this case simpler. This is just going to be a map dot Music here ratio Trace show ID. Let's see Now we're trying to figure out what is going on here Uh true Okay, so if we hit the empty case Then this works out. Okay If all of the ones that are left are dots, it's a fine Okay, here we have a trace show Ashes She is We just returning into this She's left Let's see. So I think we think this will work Uh, I think I'm screwing up here if uh Yeah, this is a case on screen. I think this one is okay Or I'm making the choice But uh, it's after I made the choice and then I'm in the case where Um where um Okay, so I I can't be in this case unless there was a dot immediately prior Because otherwise I See if it's a hash, I would always make it a dot Okay So if I see a c Then I can See here, um See why as Yes, and we're just gonna Split at See Axis and then we're gonna say, um If any equal to dot And then we want a If any equal to dot as Then it's false. Okay else case Bs of So if we hit a hash Then we are in an impossible case We hit a dot Well, then we're in a great case. So then we just go keep going options with check check Cs bs However, if we hit an unknown We have to make that unknown into a hash into a dot option c a check c s um unknown bs Axis Dot Uh Because In line 50. There's a non a non exhausted patterns in case Uh, okay Right and if it's empty Then we are also going to be empty Uh, if it's empty we need to make sure that If length a s is equal to c Then Otherwise it's not possible So what I want to be getting out here is All the valid assignments to um Uh, okay, sorry The problem here is that Okay, I should be doing like this map Yes map is Mm-hmm Okay dot hash hash dot hash hash and hash dot hash dot hash hash Okay, so we're almost there, but this first one is wrong There's something wrong with this Make dot case, I think trace show ready So hash hash dot hash hash hash dot hash Yeah, exactly so In this make dot case Okay, but that's actually because trace show yes, yes Oh, no Oh, no, no dot hash hash hash Mm-hmm So one one three Okay That's basically saying okay. I made the initial one dot I forgot to Make map Then I made the initial one dot So if I make it If I make it hash I can make hash. So this one is make hash But what I want to do here is I want to say a map c hash to options vcheck csa Same as above right uk s And actually like this dot uk s And then we get the right one. Okay. Let me see trace show Let me just see one more thing The ps is empty then If Link ps is equal to c then c hash else Just to cover this case Okay, and So now we're creating all of these But part one Uh, it's actually gonna be links So now we're a lot smarter About how we do it Let's see if it pays off First of all, let's see if it actually works on the other ones as well one one one four one one two eight one four one one four We're not quite there, but we are moving forward Ding ding ding Okay, let's see What we can do, uh I'm gonna yeah work for like half an hour more and then we will see let me just Check what the time for this will be If we make it correct for the input Okay, so it's a lot faster for the input and then I don't want to be I don't want to be doing this if it's going to turn out to Do not help at all And let me see So how many does the input have? 1,000 Let me see this was not done with runway day 11 um Let me see SIP with a part two map m print It's actually gonna be one Okay, it's going but it's giving zero for some of them Which is uh strange So some cases it's not counting And then for number 12 It's just Crazy slow Okay, so I'm not really doing it uh for part two You see for the example 116,500 So something I'm missing that's that's providing a lot of uh Well, it's a lot of them Okay, so one works So it works for Work for one three This works it works for one three and four for sure This works for both for the ones that doesn't work one the other one. Okay. Let me see Let me see um If length yes is Not equal to see any dot then 14112 I think okay Mm-hmm. Let me see Okay, if I'm looking at a If I'm looking at a hash and I need to get the album this is correct Okay Now if I have any left Just make this simple No, I mean, yeah, I need to I need to throw it out if I don't have uh if I have any Ah if all equal to dot x is if all Is actually not equal to hash then Replicate length x is Not That's the mistake. I think 1412 111411 One 14112 10 Let me see. What is the Last one doing Part one. Um Let's see here. Uh, we reverse the lines We take Take one and we uh, don't print we actually print out the Possible entries Oh, sorry. I was messing with the wrong one. Okay, and we are going to say here Take one dot reverse Lines Me too here Instance show entry where Show hash equals hash Show I know if you go to question mark Up This is the last one. Okay, and it always has to be hash hash hash And then dot And then it seems that I'm doing it in the exact opposite order What I can do that Flip that order by just flipping this So hashtag hashtag dot hash Okay That one is there and then there's two dots and then three dots And then four dots. Okay And then two hashes There's this last one that's Wrong And that's if I make a dot um, and it's because what If it the If the last one is an unknown Okay, it's not like that. Okay Okay, let me see if length Axis is less than Or equal to C Then we don't do this else Let a sbs What am I trying to do here? Um I don't want to make the hash Always want to make the tash. I want to make the next one Uh, so okay, so it's just the same as this one But then it is like that. Okay doesn't matter Then I add hashes in front and then I go to the 10 more minutes. I don't think we're going to solve this in time Okay, there's one case too much and there's one case too little This last one is not possible let's just do um We check cs and x is Case Some cs is less than It's larger than length That got rid of that case. All right, let's see Mm-hmm. Oh, there are just unknowns not being replaced Lovely so one works map part two one four one one two ten one four Okay, but this it should not be one four So I'll replicate it with dots here I split at c this should be Replicate c hash I think Let me see here where c hash is equal to Replicating c hash So it's dot we do c hash c c hash Okay, so now we've got rid of the question mark And it's still giving the correct one Except not for this one So to make this a lot faster I could just compute the numbers directly not to All these Not make all of them right And then here it will just be like one And two and something like that Okay, but now we are looking at we're gonna We're gonna take part one of the Ed after we drop Five Don't be dropped four. Okay We're getting two but we should be getting Four because there are four possible way to inside a dot there Okay So everything is correct except We see then we're doing trace show ID UKS Yep, okay, and let me see I gotta stop quite soon Make UKS hash Uh, where this one is actually MAPC hash I can actually just do dot colon drop one bs I'm gonna don't need to Look at it Make Hash and make dot Okay, let's see what it gives Okay No, let's see We're gonna say here, um Axis a Trace show Oh, let's just run it here trace show I want to trace show here, uh CCS Axis making Hash Okay, so I guess that one correct it would make the last one hash making both And let me just then write out what make hash was Hash make dot All right, I'm gonna wrap up very soon Making hash making both Okay, so here made both. Okay Ah, okay. So there it made it Seems like make Hash failed Mm-hmm All right Sorry, I'm gonna have to cut this for now. I have a meeting in a few minutes But I think we're getting quite close and I think if we make this So now we're in like debug mode Saying like okay, we're printing out all the lists seeing what's happening all I got But what we can do later is that we can Just make this return a number right Because you can see here it's always just just Looping right So this is just gonna be additions of numbers right instead of returning the actual Lists Which we should be a lot faster But okay, thanks for tuning in for today Uh, I actually I'm gonna do the meeting And then I'm gonna start streaming again For maybe an hour and a half or an hour Depending on how long the meeting is But thanks for tuning in and see you later for A little bit more of day 12 And then we'll see how it goes with day 13 All right. Thanks for today All right, welcome back to Day 12 part two I took a bit of a break. I had a meeting But we're almost there with this. I'm trying to figure out I've added a bunch of uh Annotations to try and figure out this last case And it seems to be somewhere here where we uh We are not quite generating so for this case here We just generate these two lists For this case here, but we want to generate You know, there's a lot more options on how to put the hash For example, you could put the hash Uh right away Right, uh, but that does not seem to be happening so, um Let's see So make hash making both right and then Like it makes the these two Which it made in these two That was make dot and that was make dot again Um, and then this one way to hash For dot star hash star and then these two options were made, right? So it made this one And it made this one But it seems to have not made One where it just says Hash right away So, okay, so what happens is a Is it we're in the unknown case So we're not we're not choosing hash here for some reason Okay, so let me see So why do we not choose it here? It's because, um Oh, we ended with the wrong split Interesting Ding ding ding I think if you end up with this case and you say hash Right now then you have to make dots, right? Let me see Making dot so we never get this making dot case Let me see case bs of Um Why is that so unknown case, okay Uh-huh. It's because Uh, so here actually We have to say Make dot I think let me see Let me see maybe make dot here Okay, now we get Laos cases at least So it's basically saying, um If you can't do it, I think maybe we should have it here also Okay, maybe not So basically if you can't do it With the number of unknowns that you're considering then All right, let me move all these Trace shows here Ding ding ding So now I get four here. Let me see 1411410 Hey, hey Felix Nice to have you back. Let me Um Cause all these tabs. Let's go back here. Uh, we're supposed to get 1411410 So we're getting that okay, so we're doing We're doing okay this time With part two so I did part one Earlier I worked about a bunch of part two But it's taken A long time a Let me see some map part one A map link How long does it take for the input? So our first solution took Two seconds this one Takes a 33 milliseconds Oh, on your puzzle answer was 6827 Okay, so we're not correct on the input too many left Okay But we aren't getting there. Uh, let me see Let me just see if part two How long that takes Takes quite long. Let me see Do we still have some loop in it before? Where do you generate the possibilities? Uh I did that before So I used to so first I had a function just called options, right? And this one just generates every single possibility But that takes too long So now I have another function that tries to generate possibilities Uh, but with Like with Keeping the checks in mind but it's It's not really working out Because it doesn't When it works for the example That's called part one simple So let me figure out now because it works for the example here Let me see Let's see and So we're going to do, uh inp straight file input And uh Inp L will let inp L equals lines Inp, uh, let's actually just say Then Lines Okay, so we're gonna do, uh map Lines We're going to take in a line and we're going to say, uh, lengths part one simple part one, uh L So we're going to say filter, uh, filter French filter, um, L Length.part1 Length of part one L Not equal to uh Part one simple L of inp L Let's make this a Let not Matching And then we're going to say brand length not matching So this is good, right? We have like a reference implementation Uh Options with check, right? So options with check, uh We just put it here Then we're trying to say, okay We have some options. We have some checks And we're trying to simultaneously Generate all options, but only options that are possible According to the check and then we're using a lot this We're using a lot this, um Trick with the kind of we have empty lists Let's say there's no possibility of this and then that destroys everything else But now we have a list of things where it doesn't match Let's just start, um print take 10 map L part one simple L versus part one length part one of a Not matching Let's change part one simple to not take the length So I can see the actual options and Oh, sorry entry Let's just take the first one try and solve that Ed Let me just say map m print Part one simple nm map and what's the other map Good evening We are making progress Sun X Some dollar interleave one X I don't quite know what you mean here Okay print nm some Cs is less than length of axis So this case is where it's, um Okay, let me try that Um, I still get some non-watching ones Let me see But it's good that we have a reference implementation, right that we can drop on Yeah, that didn't Didn't change anything actually Okay, this is even less Okay, um Let's actually Sort these Okay, the first two seem to be fine first three First four are fine and then The first four are the same And that's basically where we assume the two is in the First one, I think Yeah, it has to be in the first one. Okay We can actually drop because the initial Period is not is the same for both Just make it slightly easier to understand So I seem to get it right Except, um We only make one choice here Uh, okay whereas Here they we Part one we choose To make this one dot But we don't choose the part where Like we make neither of them For some reason So we are missing some cases Which is strange, right because, um I don't know, okay 211 So here we Like two And then one So it's like it's not taking the option of Not filling out this one Which I think is There are no hashes in this entry So it's all in this unknown thing So the make dot that we make it a dot Which index is this by the way? Let me see So if I do make hash Let's see Uh, but then I can't sort Because I need to know which one I'm looking at Okay, it's the first one That's good In part one Let me see trace Show C, C, S Yes, yes And we just want the Head here Trace, show Dollar Hmm All right, now it printed everything for everything else So two 211 Okay Let's see, so we split that So it's 211, okay, we split that, so we split that two ASBS And then, um There's no dot in AS So we're doing case PS of Okay, and then it's make unknown Okay, so it's just when the head is unknown The next one is unknown Yeah, so then we can make it It's a lot of output Okay, uh Right, okay, so I think this one is okay Um So the here, so for this one one Right, it is this Question mark dot question mark So if it's one It's a Okay, I think the thing is We always make a choice So if we see a dot We should also actually make Nice, so now there are no two that don't match For the part one simple and part one output We just forgot that we could make the Right decision there, okay, let's see print some Okay, now we get the right answer for part one on the input using our smart method But I think it's still gonna be Quite slow for part two See example Now part two is where we Changed up the string Let's see how long it takes for the Example a second five two five one five two It does work though So now Okay, let's take this options with check And so notice that we were only like mapping over or never actually Uh We never actually read the lists that we are generating So what we can do is how we can Take This whole thing And then just say We can make it into an integer function right Options with check and we're gonna replace that with calc Okay, and So we don't map over here. So this one just means We don't map. Okay. Here we do zero Here, there's only one option So this is actually going to be Let's make it a list of ints first um one zero zero Uh, here we have okay, it's just going to be an int really zero one Here we don't make Anything, uh, we don't map over it and instead of We multiply one Okay, let's see how fast calc ops is Read file example sum Uh, let's just do part two prime int And it's gonna be calc options calc ops Let's do part two prime here And there's no map links Which is map part two Okay, we got Some answer, but and it does make sense Because we're only multiplying and we only have zero and one Um, but if we get this right It's going to be quite fast. Let me just see If it actually makes sense Or if it's still going to be too slow for the input Okay, so even if we make it correct, it's still not going to be fast enough Oh, what's the second check? So here's really only one option schedule pluses here both nice Okay, so this one is gonna work Um If it finishes, but it doesn't seem like it's gonna finish Don't just see how fast it is for part One So let's check here We're deleting. Oh, let's keep this around the example. Okay. Now we're doing here Part one And then we're just gonna do part one right So for part one we can do it with this calc ops function in 34 milliseconds If we do it manually otherwise Yeah, oh But it's giving the It's not giving the right answer So it works for the example the calc ops function, but it does not work for Oh, I changed something back. Oh, I undid too much Good, okay So part one is quite good now but it's gonna It's taking a long time on the Input though You see I really thought making this Would make it a lot faster Okay Let's see if this helps I mean it's giving the same answer at least so I think this one is redundant You see Mm-hmm. Does anyone have any efficiency ideas here? I think because I'm just going through it and I'm calculating all the possibilities, right? Um, so not generating anything I could probably Do some Some memoizing right because I do think this make hash Um make dots They are doing They sometimes do a lot of very repeated work. Let me just keep Minimizing this a lot um One thing I'm thinking of is like We could have like shortcuts where um Okay, so what I want to check is So I can merge these two branches because this one is just gonna immediately prop right and see Same year I have a part of the whole journey. Can you do a short explanation of what the project is about and then a short explanation of what the current problem is? Uh, so we have these hot springs And they look like this like there's a map and it says Here is one group And here is another group uh, that's one and here's another group besides one here's another group that's three Uh, it says one one three right to say how many hashtags are in uh in order But it's damaged So, uh, what we get is we get these question marks instead And now we have to guess Or figure out how many different arrangements there are right? So here you might have hashtag Uh You might have hashtag so there's many ways to fill it in right so for this one is only one way but for this one, uh You say this and three two one like the first one cannot be Uh, hashtag because the first group supposed to have three and if this one was hashtag it would have four So the first one is always going to be a dot here, but then uh, there are multiple arrangements of the rest here So what we're doing is that we are summing up all these different arrangements Um But uh, and then well works great. We're just counting them all but now we The problem became a lot harder because instead of just being like This one, uh, the first line becomes all of this like all of the lines become a lot longer And the patterns are repeated so everything's repeated five times So it's going to take a lot longer to actually calculate Uh, and I'm trying to get away with it by a Making like a tight loop and just counting make dot make hash make dot Something like that, but what I think I have to do Is I have to um I have to calculate Like use the Use probability theory, right? So you there are There's a way to say this is this many ways to pick Uh A card out of four cards, uh, if you have these many options, right? Um, but then I would have to figure out exactly how many In some way, but so this one works, right? This this solution here works It's just not fast enough. Let me see. Let's see how far we get So first we have to parse all of them That takes some time Okay, it's not even doing the first one You see Why is it so slow for the first one? Did I accidentally Introduce our loops somewhere now? No, I mean that worked for the Let me see. Oh, it's just taking a long time to parse Oh, sorry I didn't comment on this sign The mile So it's a thousand lines And let me see Let's just see how How much progress we make There's 12 one here seems to be very Takes a very long time Let me just Memoize it Okay, let's keep this one As it is, but let's rename it calc ops memo Okay, this actually returns mem calc ops mem mem csx is j's cs comma x is Ah, I made it two times If it's in the map then return res comma m So here we're just going to immediately drop. We're not going to Change anything Okay, we can actually just We don't need this loop here Let me remove it here also Yeah, you can see that number 12 just takes an amazing amount of time So we really need to Get around that somehow Let me see. This is really the same case, right? Let's see Right, it doesn't check anymore Calc ops mem So, uh Mm-hmm calc ops here mem mm Calc ops mem Calc ops mem So we only we just do it directly all the time Here we do comma We're not really inserting here. It's just when we branch That's really when we want to When we branch out We want to Calc ops mem and and Okay, um make dot We just do make dot. That's fine because then we're just in the loop but if we do let i comma m prime equals make hash mm mm make dot m. This is the loop otherwise in mh res h res in md res m prime prime mm prime I'm going to leave this in here and we say oh my god Sometimes this happens in visual studio code It no matter I just need to copy paste let uh i am okay This is mh res and then this is md res comma m prime prime is equal to make dot m prime in mh res plus md res m prime prime And we need to have the where again here And then this one is because it's calling the wrong function Oh Part one we don't really need it calc ops but part two prime calc ops mem and then uh first make hash make hash m It's not giving the right answer This used to be going even slower um Make it at least give the right answer There's one and zero otherwise it's a You can find it in the map and it's correct or less it's zero comma and Here we just drop okay zero m hash zero m That's my nc res one m Um, oh no calc ops cc res make dot m make hash m make dot m Why is it giving the different answer? yesh Okay, it doesn't even work so And it's both doesn't work and it's slower So this one is deleted Okay, I need an even cleverer way of doing this Getting quite late also Okay, it's really Not doing this number 12 here What have I deleted is it just that one? That's Super bad No, there are more I feel like if I know the solution to part one I can use that to solve uh Part two right because you we're gonna take this string right and what's gonna be the number of ways you can solve that Let's see here So it's one four one one four One four one one four This might also just be Let me try and do the memoization again Okay, then actually Before I do that, I'm just gonna simplify this to be a non dot Okay, and then uh This will not be evaluated in So if it's hash Let's see this is gonna be I'm just trying to join these two branches here. Uh, not to make it faster, but just to make it Be here to program Okay, he's If it's hash then this is supposed to be Oh, then it is Uh, let's always make hash plus make dot Because if we make this so here's just rs So this rs here Rub one vs It's the same as the rs here We see Okay, we get the right Calculation there This can also just be a loop don't need to Do any drop while there It's gonna be exactly the same minus the Function call actually Let me see. Uh, maybe I can If any dot is Then I have to make the current one or dot. Okay Otherwise It's what if I make the current one on dot and then make hash Let me see if I don't do make hash here I think maybe that's the one making everything go slow What happens then? No, it's still quite slow We split at c axis Okay, and then at the first one is Um A dot then we have a whole group That contains question marks and Unknowns I think we don't have to do it like one point at a time Um, so we're targeting We're targeting this calculation here Let me see Okay, even if I make that instant we're still not Still not good What is going on here? Changing the calculation function If okay Let me go back Here and let's see if I make make dot zero As an instant Um, it's super fast Do make hash zero It's also super fast. So it's because I am Recurring twice here So make dot, uh So instead of dropping one Let me see, um If I made this instant Okay, then it's quite a lot faster Okay And we can make this instance because if here we actually know That we're gonna consume all of these And we are going to Use replacement Okay, so let me check Uh, so if I have a Pause So you do We have, um, let me just have c We have as Wait, okay. So if this is If the next one is a dot Then these are all, um Then these are all question marks, right? But it's not Let me see then we have to count the number of Ling filter is equal to Unknown A's Oh, no, this is just actually one plus my cache, right? Uh, that didn't work Because I might not be using all of them. Let's see Yeah, I said that this tight loop doesn't quite work Like you're 21 minutes and then I am gonna go sleep Okay, and now we're gonna say here Calculate some mem case Okay, if any then, um You can actually call my m prime Calculate mem mprime Okay, then, um Make it out mprime And then we do Web dot in search mprime, um Let me say here Okay, I need to insert this key make dot Let r equals plus cache In And then key is equal to gcs comma x is in r comma my dot insert key r mprime, prime You can see here r2 prime, prime Let's see what it does with a bit of memoization Wow It did work with memoization Uh, as I suspected Because there were a bunch of those same copies Let's see All right It took a long time Uh, total of four hours Five hours But we did day 12 Part two Using memoization Nice, let me Get status Get add day 12 dot hs input example Get commit Day 12 All right That's it for today. Thank you for tuning in Uh Sorry for taking so long If I just kept on with the memoization, it wouldn't work The trick was we needed to make it A bit more simple Is equal to this let's just Make it The same everywhere Let me just make sure it Still runs Okay Good Little bit memoization just add a map keys And because we're always kind of recurring into the same problem again and again All right, that's it for today. Sorry for taking Extremely long as I said, but We managed eventually. Thank you for tuning in And come back tomorrow for day 13 All right, bye