 All right Welcome to day 13 of having a code We're almost halfway through at this point After you finish task one today, we're halfway through. I changed my shirt game Now we've got a picture of a camel And it's an ahrefs shirt which is interesting because one of the sponsors of item of the code so Shout out to ahrefs They do good stuff. They make nice t-shirts. What's nothing like? Anyway, let's look at today's stats huh Similar to yesterday's problem, but you see that you know really tapering off now we're 10% We're like 20% of what's on the first problem. So Yeah, we'll see what happens. All right Day 13 Let's grab this example right away. These are just lists. No Not bad easy to parse Okay You climb the same hill and again trying to contact me else. However. Yeah, so as you know, we had this BFS thing to find the hill However, instead you will see the signal when it's going to start signal Your time to avoid lies must not be working out in the packets come from the decision got decoded out of order You'll need to reorder list received packets your possible input to decode message Your list consists of pairs of packets pairs separated by a blank line You need to identify how many pairs of packets are in the right order But it's not a list it's like a list of There's different types years Packet data consists of lists and integers each list starts with the Prakki it ends with her Bracket and contain zero more common separated values other integers are over lists Each packets is always a list and appears on its own like Okay Blah blah blah blah blah Let's just start. Oh, happy. Let's see. Yeah, I'm gonna see is a big deal here in Sweden Alright, let's start this parser. Okay data input equals a and I Or a Lay of input driving Okay, the instance instance Now we go back to date while we steal what we have there Oh We see what we have here Okay, and now we need to Import Text dot parser Combinator Brack import qualified parser Text dot parser Combinator Okay, where pars equals a so to parse an input it's a choice of R's hint or R's input parsley bars in equals read as Qualify And now this one is supposed to the choice Let's be close. Now, let's do read as to P reads at it Or no, I don't have to parse in so it's gonna be Either one of these or parse a list of input So cars Li input is equal to do Jar we open the list Then we do sep by step by and And the sep by here is So we do parts Jar Come on, then we do return I Know it doesn't like this because this will be a list of aims. Oh, no, no, this is actually I Know I think this is how you read the input now Let's You didn't put is gonna give us You can take us a file path and it's gonna read Okay, that's actually it's always pairs, right? Let's see. I think we suppose it is a little bit Okay, so it's always pairs Input right away. Okay now file path a IO list of pairs of input equal sorry file If we have lines And then we do To do the steal the chunks function, I did really have a kind of like a utile thing Instead of copying it again and again, right? Let's do that next time, man Maybe today we have that Okay chunks now We're gonna do chunks three. We are gonna say where the F a a B empty list So it's gonna be empty string equals and input a Reduce at input B So after probably a different type. Let's see F takes a list of I need to map F here. F takes a list of strings and returns a pair of input It's probably what is the problem here. Pretty much have it as a This is just read actually now do read input. An example into print CD D13 GG Oh D13 D13 RHS Okay, it seems like it managed to parse everything so First pair is this list and it's a list of list I want and then it's not a bad surprising check Okay, now Your list consists of pairs of packets pairs how many pairs of packets are in the right order? It's a package. Okay Like a pairing of two values the first time it's called less and second is called right then If both values are integers, then the lower integers who come first If the left and right is high on the right, then you have them. Otherwise, it was our lens, so it means it's true All that at least The list left based on the lines first The lists are the same length and no comparison makes the decision about the order. Okay, so this is just gonna be Convert the integer to a list if the exactly one value So one is an integer and then the other one Convert the integer to a list which contains that interest. It's only value then we try to convince it. Okay Okay, so compare input comma input boom Okay, compare a if both values are integers and So, let's just I and I Left I right Equals Okay, if we compare the Lorde The left is just higher than the Right integer. Okay, this should just return an ordering actually equals compare Can I just write an instance or instance or Compare I Okay, so we're just comparing to We can derive eq. Okay, so we compare two integers the lower integers who come first. Yeah Ggi Compare one two So it should be less than If the left integer is higher than the other one see what's our both as a list compare the first value of each list Then the second value and so on. Okay, then we go compare so list and Just do the basic list and I so if So this are the same link that no comparison makes the decision about the order continue checking the next part of that Equals This is eq compare ally So if I have a value here, but I don't have a value on the left I so if if the left list on the right and first the inputs are in the right order Okay, so We're using less than then in the right order greater than in the wrong order Compare okay ally now if they both have one element X left Lr L L Li Rrs equals case compare L Ls Compare of Compare the two of If it's less than then If the right list turns maybe maybe this is just arriving or okay if the list are the same link that okay If the left list on the right and first and return right of the right list runs over there the items first you put an order in the right order if the list are the same length and No comparison makes a decision about the order continue checking The next part of the input. Okay, so if it's eq then compare Li Ls Li Rrs Otherwise Return we just return the otherwise and we turn right. Okay now compare Li Li And I equals compare Li Okay We actually We don't have we don't we didn't just do it like this Li So we keep you know done both cases We just flip this case also just to make sure Okay, and list me then we compare these two Compare okay Compare I Lly equals compare Li Okay, so I think we we covered all the cases now now, let's see What if you do now task one input two input Okay, let's just let's just do a digit type Uncurry print map uncurry compare Dot a I think it's just map reading let's read input Yes, okay Print map uncurry compare. Let's try that less than less than greater than greater than less than greater than less than greater Okay, let's see So let's say smaller in person right order the less and less than okay, okay now task one It's gonna be pool task one equals Okay, so we got LT LT GT GT so the right so right order right order not in the right order Left side right on right Oh Okay, so these cases are swapped actually GT LT you fix that bug Is it be True true false true true true false true true false true false true Okay, so true true false true False true True true false true false true false false What are the indices of the pairs that are already in the right order? Okay So we take this sip one filter S&D map FST, and we take the sum we get 13. What do we get for the input? 5 3 3 0 All right task one done in 20 minutes. This is going Swimmingly now. Let's see if we actually Okay, now you just need to put all the pockets in the right order. This is got the blank lines In your list of received tickets Okay, so we are gonna put them in order Okay, so task one Ask one task two Take a pair of inputs input input comma input task one equals map MK so order where where order of a comma b is equal to main a b Order Now they're all in the right order You organize all the packets the ones in your list of receivables to the divider packets into the correct order Or the example is all of putting the packets in the correct order is But there's no divider packet in this example Okay, so I'm just supposed to sort the whole thing. Okay, so we just map a Sort Let's see what that does. Okay, so we got three lists. Let me let it say one one one three one one List one. Yeah, this is like it's in the right one. Yeah, okay, cool Merry Christmas. I'm your developer. I'm gonna developer has been with us for so many days. I Like it. Okay Okay, so I just I add the divider packets Okay, I just Added to the example Guess I say List list to list list six Okay, so we added the right of packets afterward Locate the divider packets to find it a coder key for this distress signal Okay, let's just not add them here Let's a We're just gonna add them on the end or in the beginning a D1 D2 D1 D2 What isn't it like this? D1 equals what it is. Yeah, so this is Lee Lee Lee to Lee Lee Lee Lee E2 B6 a lily D6 The end okay, they get at it now For example order is actual located divider packets To find that the coder key for this you need to determine the indices of the two divider packets and multiply them together The first packet is index one the second was in the top. Okay, so we don't even need to sort we can just quick select But let's not do that and let's say a Where a input Sort it equals We have to say Sort it, okay, but now we're gonna say who go Find indices, okay Now let's go back here find indices, okay, so find indices a input a I equals D2 or I equals D6 Sort it, okay, so here we get 9 and 13 10th and 14th so let's find it. This is well This Map plus one So we just add by one because indices started zero in Haskell and then we do 140 which is exactly 140. Okay Now, let's do it for the input 27648. All right We completed day two day 13 and we're more than halfway through Took us half an hour and why Well, you guys say Haskell is super good at When comparisons and sortings and data types and all that, okay, I thought it would be harder today. Anyway, I'm glad it was not Nice to have a bit of a break Okay Now let's write this utils function. So let me create a new file here Util.hs, okay, module Util where? Let's say write the chunk song here. Now, how do I Can I I cannot refer to it, right? Unless I do like What if I do ght Day 13 day 13 Day 13.hs. I won't be in the wrong directory. Oh my god Day 13.hs Okay, so What is here, but now it doesn't work because these are all supposed to be nice and now can I do Import utils Can do it like this? No. Ah, sweet. Okay. So now we just do it like this. We have this util file here And then we'll use that instead, right? What else can we What else can we what else can we do here? Okay, I think we'll keep it like this for now now let me go do a Day 13 Day 13.hs, day 13 input Day 13 Get add util.hs Okay, and Some people have written I know like It will get the example Like they have a tool that like down anyway, let's just leave it here and All right, I think we're good Get status, rm, rf Let's push it get Rm, day, just let's delete all these Rm, day 2 Day 2 Rm, day 3, day 3 Day 4, day 4 Day 5, day 5 Day 6, day 6 Day 7, day 8, 7 Day 8, day 8 Day 9, day 10, day 10 Day 11, day 11 Day 12, day 12 Day 13, day 13 Get status Now we will always just do like gco xa Day 13 Day 13.hs, right? And then we will time the exit Get status rm day 7.7 rm get and gist.hs and day 13 Get status And now let's add to the getignore Co.getignore We add this exit Get status Get add.getignore Okay, this is a better organization, right? Get commit and day 30 Get push And now we write get status and there will be nothing Okay, cool, that was it for today Quick and easy But thanks for tuning in And let's hope it keeps being this easy But, you know, the past couple of days have been hard So it's good to have an easy one to keep our spirits up Alright, thanks for today And see you tomorrow For some more streaming Alright, bye bye