 All right Welcome to today's stream doing it a bit earlier Just like yesterday. It's just better to have some more time And I want to go early to bed today Anyway, today we're doing day 13 of Adent of code. We did day 12 yesterday Took us like four and a half hours But we finally did it we were We had the right idea For a while, but we just needed to memoize And after we got a memoized it all worked out Anyway, let me know how the audio is Because that's kind of the biggest thing that I can't see I added some compression now Maybe it works out. Anyway, let's see day 13 has Let's look at the stats first Huh So it seems easier part two at least then part 12 Like there's a less of a ratio there. That's that's good. That's promising We're lava island this one is for the outside Icelanders there. Hey little landing Happy Lucia In Sweden Um, let's see. I don't see any lava Full of mirrors, okay Some of them have fallen Mirrors are flat and shiny They have As you note down the patterns of ash and rocks, you should see it as you walk Perhaps by carefully analyzing bad piece patterns, you can figure out where the mirrors are Let's copy the example The input is kind of the same format as yesterday So I'm going to go ahead And copy paste this entry function, we don't need to split on Let's just copy paste all of it Ding Oh, they have gilja good. Yes indeed Gila good is Another Icelandic Santa Claus, let me say map to entry Uh But we uh, we want to split on Let me see. So we take in I guess and we return list of list of entries we take in A list of strings of the whole thing and we do map parse row On split on parse row and Let's see We wanted to do a list a list of entries. So split on So parse row Should take in Uh, you have to map map parse row Now parse row takes in a string Returns a list of entries Okay, so split on So we'll take a list of strings and return a List of list of strings, uh, okay, you can want to map Mm-hmm. Let's first just see what we're getting something mixed up here. Okay, split on Empty string Just see what this does for the example Do read file Example print dot There's example done. It's we're not gonna parse a row yet to see Day 13 and day 13 odd hs and time Day 13. So today is Lucia, which is like a Swedish Celebration of light And it is quite nice So, okay, let's see parse row map So it's going to take a one string Have to entry To entry Okay, so maybe this is list of lists of entries Map parse So now we get a list of lists of entries. Yes, okay Perfect we parse the example To find the reflection in each pattern you need to find a perfect reflection across Either a horizontal line between two rows Or across a vertical line between two columns Okay, let me see in the first pattern In the first pattern the vertical affection is across a vertical line between two columns Yeah, okay In this pattern the line of reflection is the vertical line between columns five and six Um because vertical line is not perfectly in the middle of the pattern part of the pattern Column one has nowhere to reflect on two and can't be ignored Arealicum has reflect on within the pattern must match exactly Column two matches column nine, column three matches eight, four matches seven And five matches six, okay The second pattern reflects across a horizontal line instead between rows Four and five Okay, what do you get after summarizing all of your notes? Okay, let's just say let's just write the function that finds that reflection So what I'm gonna do is I'm gonna So for let me let's check the input. So I want to see So none of these Is extremely long In the column sense So essentially what we want to do is if we We want to see say For each line, where where are the possible reflections? Right, let's see reflection It will be very good if I could actually Look look at something from both the front and the back easily And to do that we use something called a data dot sequence Which is this thing called a finger tree basically that list lets you It's a just a list That lets you um, it's a little bit more expensive to maintain, but it lets you access the front on the end At the same time let's see So we're not gonna have We're gonna have a seek of entry where, um Let me just put the language in here GTC 2021 Best language EU Import data dot sequence seek Import qualified data dot sequence okay, and So here we're gonna return seek entries And we're just gonna do uh seek dot from list mm-hmm Okay, so now I have sequences now i'm gonna say um from For reflections It takes in a sequence of entries and returns a um a set Data dot int set int set and we're just gonna return the set of possible reflections Import qualified data dot and set Yes, I s Reflections Okay, so I'm gonna split That so so also this has a lot faster split at which is good Okay, um mm-hmm Let's see may seek Equals okay, um map flip split at Seek dot split at seek a Zero to seek not laying links seek Let's just print the splits Okay, um So this is a list of list of seek entries. Okay, so now let's Take the Head dot head Okay, we're not gonna map in it There's gonna be a seek of entries just just while we hack away. Okay And now I just can say reflections It could always be reflected entirely on the Zero axis so we're gonna reject that and we're also gonna reject the One that reflects entirely around the other end Let's say here. We have all the splits Mm-hmm In the first pattern reflections across we're going to so the arrows Okay, I think maybe we're doing overkill with the sequences, but Let me see is our reflection split. Okay Is ruffle Is equal to so we have a split here ABS is equal to um if Take links a seek dot links a if take Is equal to This is actually a Is equal to Speak that take seek dot seek that length a Yes Seek that reverse I think it's like that. Let me see. Um I know it's actually the opposite So we actually want to We want to we want to We want to reverse a Okay, let me see Seek that reverse dollar seek that take Seek that length BS out of a is Equal to Map is ruffle splits false false That didn't work Right because we want to actually reverse a first false false false true false true false Let's see, uh filter seek not Filter is ruffle splits Okay, so Okay, and then I think the answer here is just um arrows Do so much better add up the number of columns up to the left of each vertical lift line of reflection To that also add a hundred multiply by number rows above each horizontal line of reflection, okay? And so then we're going to just create a map seek dot links first And we are going to make this into an inset seek dot Is dot from ask list Did Now we're going to drop the head here We're going to map reflections over the first list from list five seven from list five from list five okay And then we're going to take the We're actually going to take just let's do it like this seeks Okay reflections seek so we're going to take a The intersection of all of these seek dot inter set dot Intersections Is that intersections? Mm-hmm Let me see full l one Set that into I fold r one Is that intersection Fold the lower one fold r one Okay, let's see part one Takes a seek of entry um So we want to do this, but we also want to do We also want to do the transposition And so what I'm going to do is actually I'm just going to make this a list Okay, and then this is going to be seek um What we are going to say li seek is equal to seek seek dot from list li Okay, and this is still Let's say this is li s and we are going to say fold r one Dot Is that section of Raffle is equal to this Is from Okay, so one raffle is basically what previous one did and Folder dot map Uh one Seek dot from list Dot Uh And then so one raffle dot Take that from list So let's see here Reflections All right, and it's because I am still doing seek not from list here Which I don't need to do now No, this is not this should be just This should actually just be Like this Okay, um So let's see and so let's Just make it into a number so park one takes a list Of list of entries To an hint Part one is equal to okay a So, um, how do I get the element out of the set? Mm-hmm Okay, I just do lm's Part one uh case um Is dot lm's So we have e reflection Of e Um of So if we have something Just one I Then it's a vertical reflection Which is great and then we do We just return Otherwise We return Case is not lm's of Reflections of Transpose e right so then we're doing the Horizontal one I think um of j to j Otherwise This is from data.list So here I want to say not map reflections but map Part one To five and four So j times 100 And then we take the uh sum 405 what do we get for the input? Did I Pace it in the input yet? Let's see There are no raffle let's see let me see Like this let's just say error show access I just want to see if we got multiple Or if you can get any reflection Of the transpose, uh, let's just see This is kind of funny. Okay, so it works for both the examples Mm-hmm Let me see Is it Literally the first one that crashes Okay, the first one crashes You see Let's show Because otherwise Let's see here Trace show ID from list For list five seven five five seven and then seven seven Eight seven seven seven eight seven Ah, okay. Yeah So the four six four okay From so eight twelve eight twelve eight twelve Eight twelve eight Eleven eight twelve eight twelve from list Empty It's saying that this one cannot be reflected Yo, hey mad flash. How are you? Today Yeah, I can be your Haskell guru. What is your Problem? But it is reflected here right eight And then this one We got this one we got this one We got this one and This one should be reflected right Is the transpose going on? Let me Oh, okay Let me see I don't think I should transpose the whole thing. I think the transpose passes it up um What I think I should do is I can I don't have to transpose it I can just I can just um If I don't do it with so let me see Um, I think what I can do is Just treat it as like all the lines and just reflections Of e Reflections So I want this to be Reflections So eq a List of anything that can be equal to A list of int sets That's how it was in the beginning, right? Map one raffle This should really return int set And a folder one I guess that intersection One raffle here thoughts on Christmas music or background I like this Christmas. It's like lo-fi Christmas Which I I like it. It's very, you know soothing It's a It's nice programming music, right? It's not like grabbing your attention. Usually I listen to more techno harder stuff, but This is kind of nice for The chill vibe, you know So what I want here is I want um I think we should take this out from here, okay, and um So exactly so so we're gonna see So we're just gonna operate directly We're gonna say a one raffle Uh case is dot lm's Uh One raffle dollar Seek dot from list E Then it's items a hundred otherwise So the none of this transposition business for just check first if there is a If there is a vertical horizontal reflection And otherwise Okay, that worked for It still works for the example But it's not working for the other one Okay, and It's always annoying when it works for the example, but not the input And you have to kind of do this It's Okay, let's see Let's just print the Example that we are This is the first one And we want there should be a reflection here And let's see Seek dot from list Mm-hmm Okay, and then one raffle and it's not doing that. Let me see we're just commenting everything out Uh now I want to see the splits here One raffle Stevie the angel Okay, so if we take the first line And then we match it up Mm-hmm It's confusing that it actually that it works for It's confusing that it works for So where should the split be? Okay, it should be when we have One two three four five Five here Okay, so that's So here we have one here. We have one two one two. Okay, and then here we have one two Three and here we have one two. No Yeah, so one two three four So it's in this case one two Three four five Okay, so Um Mm-hmm Let's just do trace show and e and Okay, and it's not filtering the Israel policy Mm-hmm Mm-hmm What is my distro? My distro is Uh Windows 11 But I am running this on a Ubuntu 20 server in the cloud Plenty of memory and it makes it easy to Just I just has this h into it and then you know I can Use the gpu and game and whatever on my laptop. I used to have a desktop so it made more sense back then But that one died Let's see because it it's working for um It's working for the example So what goes wrong here? Let's see trace show ps Yes, we're just importing debug dot trace at this point Uh, let me see and uh, uh, we're just gonna name this something else um where ref a is equal to This part Mm-hmm Now let me see Mm-hmm Trace show uh rev a Rev a this is ref a let's call it that ref a rev a rev a equal to trace show ps a comma ps Mm-hmm Okay, what is going on? Here so This one shouldn't work But we're talking about the one with five in it one two three four Okay, so it's this one that should work Mm-hmm. Okay, so the last two are the same These two are the same Ah this one and this one are not the same Oh, okay, so they aren't the same so where is the reflection here? Maybe it's uh, maybe it goes the other way No, wait Yeah, I think the reflection should be down here, right? Okay, so it's a vertical reflection that we're missing Okay Do-do-do-do-do-do Is it gonna be a mess? Let me see. I think it might be just because we have a Mm-hmm I think it's because we don't uh, we should take We should take it both ways. Okay, so let's see Ref b is equal to seek Not take c Not length a A s dollars c dot reverse b s Ref a equals b s or ref b It's equal to s. What does it say now? Okay, still works for the example, let's see Definitely copied it correctly Mm-hmm Let's see where where uh, or is equals this 30 equals Case 30 I have the lms of horrors And here I want to print out her show Horrors 30 Do-do-do-do-do Let me see. Okay. Okay. So this one also allows for the other one Um, but this one. Yeah, it's not correct. This one always gives an answer, right? So what is the reflection here if I put that hashtag there I do get 800 for this one Um, but there is no hashtag there Okay, let's see. Uh, is it reflecting across this one? No, so it doesn't miss my cheer in here. So it's not that one It's better line reflection where the glider goes. I'm six. Okay, then it's just It must be this zero, right? Otherwise, it's just zero because then we have to reflect We can reflect across that axis I think that has to be the case, right? If there is no reflection Then it has to be the case that We are reflecting across the whole thing I don't think that that doesn't feel good as a solution. But let's see If that is the case The answer is too low Because we're missing some of them To summarize your pattern, let's add up the number of columns to the left of each vertical line of reflection Uh-huh. Let me see It's gonna be let me see um I think I think it's just i'm gonna be um sum map times a hundred Uh, or is sum plus sum map plus sum of 30 So I think might be this right? They were just uh Because sometimes we might have two lines Sometimes we have zero lines and then maybe that works still doesn't work Ashen rocks easy walk Where is our okay? I cross either a horizontal line between two rows Or across a vertical line between two columns and my input See this one doesn't match right because this was one extra one here So there are zero in this first one, right? Let me see maybe Maybe lines can go through um Let's see Maybe they can like go through a specific line, right? Look if it's so these are both even number but maybe Maybe we can like reflect across a certain line. Let me see print a map e length e length and e Okay, so these are all These are not But these are also odd numbered So they all have odd numbers here So that's not the problem I'm finding it hard to figure out what to do if there is no reflection Let's see I cannot reflect between these two columns No because of This one and this one tell you don't match I also can't do it at the ends There is no reflection here in this first one Is my input just uh fucked? Okay, there's no Okay here at least two you could maybe Yeah Okay Let's see. Does this one work? Okay, so these two reflect needs to reflect and these two Reflect needs to reflect and needs to reflect needs to reflect and needs to reflect. Okay, so this one There is some bug here At least because of the second one it should not be giving it should be giving a vertical reflection Same here actually There is a vertical reflection right here So there's just messing up some of the one of the reflections. Okay Okay, there's not the input that is fucked. It's something wrong here Okay, so let's just Let's just do the reflections of the first one head reflections Okay, and Let's do um map map one raffle Seek dot from list So I we want to see um So the first one and this so the second one and dot second So we should see this one as In this first list Let's see So we have this mm-hmm Let's see uh sip um map is raffle Okay, let's just see map is raffle splits splits Uh Because it is um, I think it's because it's reversing I think we got um So here we want to um We want to take the Okay, we want to take Okay, I just messed up this We want to uh say seek Let's just do it like this We want to do cq dot take seek dot length As of Yes Ref b and I want to seek q dot reverse that Okay, and then we should get that as is equal to Ref b I think it was like that. I think I just messed it up when I copy pasted something Okay, so this is the splits Okay, then this one seems to be okay now let's uh Okay, that doesn't work on the example for some reason Okay, let's see Okay, so it's either like this. I think Maybe we just have to do ref a here also Ref a Yes Yes Or Okay, so I think We need to do a combination of these Okay Let's just uh save this one And now we undo everything Mm-hmm Let's grab this one as well Let me redo everything Okay, so, um Ref b This is the first case and then We have the other case like from the other direction, I think Ref b ref a is equal to yes Okay, this one seems to work Let's see if this gives us the answer for Input as well Okay. All right. We did part one. Good took us a bit longer than we wanted, but We were quite close. We're just doing uh Oh We're just doing it Not quite accurately. Okay You can add a one thirteen You just input for example You commit m 13 part one Okay, let's see what part two is above Upon inspection you discover that every measure is exactly one smudge One dot over one slash In each pattern you will need to locate And fix as much that causes a different reflection line to be valid The first pattern smudge is in the top left corner If the top left were instead Dot it would have a different horizontal line of reflection With as much in the top left corner repaired a new horizontal line of reflection And now seven has no corresponding to that rock. We ignore Like for the fifth symbol On row two from dot two slash Summary she knows before but they see it use the new different reflection lines Now let's uh, let's write this again So this is for the example, um In this the first pattern is new horizontal line has three rows above it So they becomes they make a horizontal line, right? Let me see what does it say for reflections let's see, um One raffle for the horizontal ones. It's actually One raffle dot seek from list Then it's just going to be empty, right? Yeah Stir Then Okay, and Let me just now write Um now we're gonna map get splits Here for the horizontal one Hmm Let's see we're looking at this example here, and they're saying if I If we so we have the horizontal one here What do we have to change? Okay If the top left one says dot Oh exactly one dot or star has to actually be the opposite type I mean there's a naive way that kind of just changes Um changes every element and then just runs the whole thing But it would be nice if we had some master way to do it New horizontal you need a new line. Let me see Okay picks as much it causes a different reflection line to be valid Okay, how do we want to do this? We really want to see if um If changing one smudge would Make it have a reflection line, right? Let's see so splits is like this is raffle. Okay. Um, let's see Splits a rough non rough equals partition Is raffle Splits It's right here actually Okay, um And then this is map again So is raffle ASBS Let me see This is going to be a sequence of a and sequence of bs Let's count how many are different. Okay, so I want to see, um, is there something called, um seek dot sip Let me see let's see AS ref b equals seek dot sip AS ref b Uh, and then ref PS ref a equals seek dot sip a PS ref a Okay, and now I want to See how many of these are not equal seek dot filter Um, okay, let's do the same for the other one Hmm So then we do save AS ref b is equal to zero or PS a It's equal to zero Let's copy this here Just to see what we get for just to make sure that we're still Doing the right thing We're not getting the same thing Equal eight seven seven AS equals ref b Or ref a equals bs Strange right I would have thought that If I take the sequence Let's see res equals this AS ref b trace show If res then trace show AS ref AS ref b comma AS PS ref a Trace show true Hmm seems like this one is always zero Ref a equals bs No, that was not the case Let's see res one res two if res one res two true Okay, so this one works Now we're trying to figure out if res one and AS ref b not equal to Zero then res show res one AS ref b true else if res two and bs ref a not equal to zero and trace show res two comma bs ref a true else false So res one is that AS Okay, because I sip them together and And then I only check like the prefix, right? I think that's the problem here Rest it like this if res one or res two Then trace show res one AS ref b res two bs ref a res one or res two Right, so I think the problem is when Let's see links AS Because sip just stops The sip might be zero, but otherwise might not be bs ref a So then that's false and then AS ref b Okay, right because I'm only If I'm only taking the difference here, okay so we do need to We do know to check it And let's see true otherwise um Or a bs ref a is equal to only a difference of one here Okay, so let me see trace show AS bs So here it's saying that if that so there's a difference of one How do you do coming up whoop whoop that's what I'm here for Hmm Let me see what if I don't do that just this way, okay? um One raffle one raffle prime Is equal to as ref b is equal to one Or bs ref a is equal to one Mm-hmm So yeah, I think this needs to be um, basically Length AS is equal to length ref b and The difference is one length bs is equal to length Ref a and the best difference is one. Let's see what they say here about We have to be careful that it has to be It has to be all that has to be the Has to be the right index, right? so now we're gonna get like Clean here the difference is just one Okay saying we could flip it on Between three and four Well, this is the Okay, so it does find the three here Mm-hmm But it seems to be finding more than just that Some healthy man Not bad. Let me see you actually just Let's just see if we can just get away with Something super lazy. Uh, none of this one raffle business Part one prime. Let's go back to the one it was uh Case Verity of i to i times one hundred Otherwise a case horrors of j to j Otherwise error Now let's see what part one prime gives us Hmm. Did I do this one? Oh, maybe like this. Yeah Okay, so this one is fine Okay, uh part one prime Let's see because it's not taking very long, right? And opposite I have to go to dot opposite Dot equals hash equals dot So, uh one change Takes a list of entries And returns a list a list of entries Okay, and then one change Let's just see One change, uh empty is equal to empty If we make one change The empty listed we don't get any More now one change x axis is equal to Let's see one change of I can't make a change here now One change here is going to be It's going to be a opposite x Axis and x That's going to be one list And then it's going to be It's going to be like this map opposite x over First is the one that's unchanged Oh, sorry Maybe it's not a great way to do this How many are in one of these? I feel like we're spending time on this, but it's just going to be Crazy slow Let's actually do one change on List of list of entries is going to be a list of List of list of entries Okay, and then we're going to say one so where uh indices Is equal to a comma b to a b comma b over zero to One change Ease And this comes here to length of e And it's the x coordinate and then we're gonna have zero to the length of Ease Which is equals Indices and let's see where we get here If you do read file example Into print One change dot head dot bars Hold on Okay, so this one is giving me all the Indices Now these are all linked lists, so it's not gonna be It's not gonna be great performance On this Well, let's say map change indices Change indices Change And this is the y-coordinate and this is the zx coordinate and the y-coordinate Ease equals and Where a comma b is equal to split at Get to x b b s split at y Ease and then x I y's Equal split Okay It's the i and j And the split at j and then this is did at i a b Then this is equal to a Concatenated with Um x opposite y y's Let's see map and print Making all these changes is not gonna be fast print Okay, one change map change indices and wait It you're not taking this I'm gonna print the head For one change We're taking the example and we make one change Yeah, okay, then we change zero zero map m And I think it's actually not length e but length e minus one A part one okay now part two entry to int Part two is a e So first we do Where p one equals part one prime Um, so here we just say zero part one prime e and Let's see now we're going to map part Part one prime over uh one Change e And I just want the head of this and filter Not equal to p one Let's say this should work on the example but Might not work So it's not equal to p one x larger than zero and Mm-hmm Let's pause for a minute and say and Just print map part two And let's just do uh Part one prime One change e Okay, so now I want actually I want this to be a bit different I want the part one prime here to be The list of integers Okay, so we're actually going to have it be a list event So this is just going to be a rarity with map 100 times hearts And we're just going to do conkat map here Conkat map Conkat map part one Conkat map Mm-hmm Okay, and you slap this in here. You know, we just say and and not equal to Not equal to p one uh dots um Okay, that's not too bad Sure, it's gonna be hella slow for the input Let's see Oh took only one second. All right. We did day 13. Whoop. Whoop would have been nicer to uh To figure out like a clever way, you know with uh We start just making the changes and going for it but You know, it's not too bad Let's just make the opposite here Yeah, but like, you know, if it finishes in one second, that's fine I'm dinging. Okay, let's uh Erases one ref prime. Yeah, we spent too much time on this um, we could have just At least tried the negative way right away And then seen what happens, but It was good. Also, does you see what was happening? Okay, let's uh commit this git and day 13 changes git commit and day 13 git push. All right That's it for today uh We didn't do any super crazy pricks like green theorem green serum or whatever, but We got it done and we got it done within a second and that's A That's all it takes Thank you for tuning in and see you tomorrow maybe We might do a short stream tomorrow just uh Yeah, because I need to pack because I'm going away So tomorrow will be the last stream for a couple of days, but otherwise Thank you for tuning in and Yeah Enjoy