 Hello, welcome to day eight of the advent of code in Haskell Yesterday we solved it quite efficiently 100 milliseconds after we made it a bit too parametric. We interfered with like inlining and stuff like that But We're gonna do it again today and you can see that my T-shirt is mirrored But that's okay All right, let's just get to it and Let me know if what's up, right? city date Make their date city date code period and Let's see Yo, let's just open folder So like that now we Do-do-do-do-do-do Good day check it out My god, this looks like a lot of work Okay, seven-segment search You barely reach the safety of the cave when the whale smashes into the cave by collapsing it Senses indicate another exit to this cave at a much greater depth So you have no choice but to press on as your submarine slowly makes a way through the cave So do you notice that the four-digit? Seven-segment displays in your submarine are malfunctioning. That must be logo Right, okay Each of the seven Each of the digits of the seven seconds is rendered by turning off Honor of any of seven seconds named a through g Okay, so to render one only segment c and f should be turned on The rest would be off to render seven only segments a c and f would be turned The problem is that the signals which control the segments have been mixed up on your display The submarine is still trying to display numbers by reducing output on signal Wires a through g but those wire are connected to segments randomly Worse the wire segment connections are mixed up separately for each of the four-digit Each four-digit display all of digits within a display use the same connections. Okay So you might know that this only signal wires b and g and turned on but that doesn't mean segments be a decision Okay The only digits that use two segments is one so it must mean segments c and f are meant to be on With just that information you can still tell which wire bg goes to which segment c and f Yeah for that you'll need to collect one more. Okay, let's see So for each display you want to change the number one make another for all 10 unique signal patterns you can see And then write down a single four-digit output value Using the signal patterns you should be able to work out which pattern So, okay Let's see. So Here's what you may see a single entry in your notes The entry is wrapped here two lines so that fits it well Like unix and so on until your limiter finally the four-digit output value I mean, there's a lot of stuff to parse here, right? Okay, each entry consists of 10 unique signal patterns An order limiter and finally the four-digit output value So within an entry the same wires segment connections are used But you don't know what the connections actually are The unique signal patterns connects to the 10 different ways the submarine tries to render a digit using the current wire segment connections Because seven is the only digit uses three segments dab in the above example means that to render a seven signal lines da and b are on Because four is the only digit uses four segments eafb means that To render a four signal uses eafb and you are on Using this information you should be able to work out which combination of signal wires correspond to each other 10 digits Okay, so we get One two three four five six seven eight nine 10 Okay, so we know that for One it's going to be two For two if it's three it's going to be Seven And if it's four it's a four Okay, now focus on the three easy digits a because the digits One four and seven each use a unique number of segments you should be able to help each combinations How many in the output values how many times you did each one four seven or eight appear? Okay Let's take this here Counting only the digits in the upper value support after There are 26 digits that use an unique number of segments Okay, so we just count like how many there are of three and how many there are okay Task one seems to be pretty straightforward Now let's say create it new file Example paste it Make it bigger New file day eight dot hs module main okay, so read input Uh, we're going to take a file path and we're gonna return So for the first one we just need the links But we should I think we should return the uh, let's just return the The links read input One hello yellow I was going to say a little any show up. Okay. Uh, so this is read input one for task one And let's say here, uh, this is gonna be Map, uh, and then f over lines I've map over read file and it's gonna be IO and then f here That's a main Main equals read input one example Fed into red input one Now what's wrong with this one? It Couldn't match All right, we are mapping f over On landlines like this Now where f has a type string to list of ints F equal and f defined Now this one won't work because right we're going to feed it into rent Now, uh, so we we don't care about the actual letters We just care about Um How many times did you one four seven or eight up here or eight? Okay, so, uh, is unique Okay, so we're just gonna take a drop while Not equal to This one over, uh Okay, so we drop until we get to All right, so it's not gonna be Okay Let's look at the puzzle input. Yeah, these are like per one per line, right? So I think I just copied this wrong Like this and then we drop until we get this Okay, and then drop while not equal this and then we do mapling Dot words Let's see Hey, I love it. Nice to see you again 8.HS and Day eight, so we're just gonna write okay, so we get one seven five six four Is that correct? No Oh, okay, right And that's tail Because it's like it's always has the space in the front, right so seven five six four. Let's see Oh, this is the input Seven Five six four Okay, and now So the one is two digits uh Seven is three digits EAFB is So we do We do our classic Group sort and so I think like the first one should be pretty easy Uh, that's actually just group first Our sort first so four five six seven two three six seven Let's make these into just sets. No, we don't want to set Uh, we write our classic function group This is gonna return list of income on end And comma and and then Map underscore to x comma length of l So we want to see like how many each one Is there And then we let's do For data dot int map as Int map then import data dot Int map as i am And Import yeah, this is supposed to be Qualified So we are gonna go i am dot from list And it's gonna be int map int So now instead of returning a list of keys we return a list of int map int and Okay, and then Um And then we actually We write here We say count unix i am is equal to A map maybe Uh i am dot i am All right takes in i am first So this is from data dot maybe Who would do i am map maybe Uh, what does that do oh no it maps over it right we want the one from data dot maybe import data dot maybe map maybe Okay, so this one is i am and then we want to say the unique so that's so the one So one has two Let's see So it's we want to have two We want to get the one that has a three And four three and four And then for eight it's uh one two three four five six seven right yeah, which is all of them some So this is gonna be here You don't actually need it globally So you say sum Count unix No What is it complaining about now? Now it returns an in And now this should return an in And then we see how many are in each line And then we map some over that We get 26 for the first one now. Let's run it on the input new file Input So I think the first one yeah the first one should be Not too bad, right? I think there's a lot more because we will have to actually figure out what the number says or whatever But just the first one should be easy 488 that's not bad I mean how long did it take us some int maps three milliseconds 10 sometimes Sometimes zero or six minutes like that. It's uh, at least nothing to worry about Let's see if it's correct. All right, we got the first one Okay, now we have to Probably Continue to partner now we have to Oh, okay, so the unique signal patterns would be abcdfg eight Or ap is one of the four digits. Well, you can read right city fab Okay Okay, so we should first consider the fact that That the uh That these like city paf like it doesn't matter the order they're in right they're all doing the same Segment So okay now let's do read input to file path and this is going to be a pair A list of a pair of string list of strings And uh list of string Read input two That is equal to map f map map f dot lines Read file f2 equals And defined undefined Uh, what is wrong with this one? It's not being we're already f mapping. We have to say io Okay, now here this is going to be It's gonna be span right span. Yes So this is gonna be so uh, all right, so Here we have the ln right now where uh like the Segs and then the we get this character this character And then we get the space character and then the rest Is equal to span not equal to this character lm so this is gonna be uh The words sags words rest Now, let's say try this on Read input example Ding ding ding ding so we get the Strings that makes sense Okay, so, uh, let's actually um Now let's sort those right let's map Sort Over the words and map sort Because it doesn't it doesn't matter what order they're in right So abcdefg is always gonna be eight okay, um So we actually yeah, we never have to figure out the eight because abcdefg will always be eight Okay, so, uh Let's draw it up right. Uh, what did we maybe we can copy paste the picture from here No, let's see abcd. Yeah, okay, let's actually Let's grab this one. Okay, so we can um Let's always map sort and then we let's say, uh sort by compare on lengths for these And then we can say like the first one will always be that b and then this one will be bd e Okay, uh, so and we always get this right Now, okay, so for the seven so this top one here Will always be the one that is Like Always be the one that's Like in the first one, but not in the second one Okay, uh So let's just call it like this, you know, let's just figure it out Okay I think I have to paste it first actually And Dean So let's uh How do we do difference set diff Uh, we don't need to sort actually here. We need Let's say map set dot from list Ding ding ding now to do this we need to import a data set as Set so this is going to return us a list of set A list of a set of Charters How does that look can we actually sort by length also there? From list be from list be okay So let's write Let's write the functions A lot of imports We are just doing it our way Okay, so So first we need like a so Canonical So we know we Canonical seg disc Canonical seg disc of a b It's equal to one right kenan Kenan nickel. Let's just copy this. So how do we write two we go? To to to to to two is Okay To d that's gonna be A Canonical seg display so like D a f g c Um, but we have to order it but so d a c So it's a and a b c d F g So that's two But we're gonna do this for all the numbers. Okay, so how do we write three? We do D a so we so it's a b c a b c d f that's three So the for the four, uh, it's gonna be a a b e f Canonical seg disc five How to write five that's gonna be D e f b c so b c D f e right Uh Like this one. Let's be b c d fe equals five Canonical seg disc six is d e So b so b c D f g e It's gonna be six A D e f b. So we're definitely gonna screw up here. I have to fix it. Okay. How do we do seven? That was the three one That was a a b d Seven and canonical Seg disc a b c d e f g That was the eight canonical Seg disc of nine But do we actually have a yeah, we have zero as well, right? Yeah, okay, we probably have zero as well. So zero is going to be a b c D e g and uh, canonical seg disc nine Is going to be final one. Uh, a b d f e Nice. Okay, we got our canonical seg disc This is actually going to be string to int Okay, uh Now to find the canonical d. Okay. Let's see Find d. Okay. Uh, so we have Our input, right? Like we have this These sets So the d Is going to be So d Is going to be a let's write the canonical ones Okay, so the yeah, wait, so the d is going to be okay, so let's write this down fine D so we have the list of set a char And it's always going to be a nine element list And and there's so this this is one this one is going to get us a char Char okay, so find d of and then we just look at the first two a One a seven And then the rest It's going to be the a seven a set One This is one word I uh, oh wait, isn't the other way right? Why is this not working? Yeah, I guess this is a set and then we take the We'll go a set a to a And okay find min Or we can do head. No, let's just sue set dot find min Okay, so we found the d here Okay, so to find e Let's see. So okay, so we so we know that uh, we know a and b We found d Okay, so now there was one with like four right? That's the four a b e and f So that we can find the e and f find e and f one seven four a Oh, yeah find e So let's actually e and f This is going to be a List of set of char To a set of char So this one is going to be Four set dot slash slash one right so we remove a and b here and we get the e and f Okay, so Okay, so To let's see a b d f e so we found e and f a b c the Shit So this should be here, right? um d e f g. Yeah every city The b c d e f g I don't even remember the alphabet e b c d f g and Okay, so Now we know how to find d and we know how to find e and f Okay, so we know how to find d and e and f. Okay, so Uh, so we can remove okay, so Find uh, let's see. So here we have d e and f so find b set of char To char. Okay, so find b Le is equal to So where d is equal to find d probably uh, okay e and f Is equal to Let's actually here find d. This is just a set of char And we know it's going to be one thing but like it's fine So find b is set of char as well So to find b Right, we say we find d and we find e and f of the list and then we have We have the one that's number five. Oh, but we don't know which one is the fifth one. Let's see Okay, let's order them by Yeah order actually But yeah, you see this one is just going to be a bunch of uh us trying to kind of figure out how to Figure out each of the letters Oh my god, so I so okay, so we can't really find Now in the next one basey d e f So a b d e f that's going to be nine So that's going to be uh If we want to find nine Okay, we don't know which one is which So we can find the nine here by saying it's going to be the one that's a b d e and f Uh, so we can figure out what the nine so we know what the eight is We know we know these three Um, but we know a b and we know e and f Do do do do Okay, so if I remove a b from this one I have cd Let's see Okay, let's see. Let's let's find it. Let's figure it out Uh, so so if I remove let's see. Okay. Let's copy these right Now I know I if I if I know the a and b's right if I remove those We get this a b And we move a move a and b and b I remove b a and b Are you move A and b I remove b I remove a and b Okay, so I can actually figure out what the six is Are you moving the B the b. Yeah, okay Okay, let's see because It gets like a unique link after removal Oh, no, I'm doing it wrong. Sorry about that. Okay, so this one this one this one this one This one this one This one this one this one Okay, uh Let's see Find eight Take a list of set of char Set char and it's gonna be find eight is equal to Le is equal to the last of le So that's the eight. Okay Find six is going to be le So it's gonna be one and the rest May let's say this is like a list without eight, right? So this is going to be one and then the rest This is equal to uh So let's see. Oh my god gsi in its In it In it. So this one so we get the so we get the In it of rest. So that's going to be everything without the eight And then we map set dot remove Um And how does it work? I think it's like yeah set dot remove One from the rest and this one should be this you've only be one left. So where Res equals this is res So we found the six Let's actually test that. Okay. So if we found the six then we can find the zero by removing the six Okay, so let's see Let's say Let's write it like this. Okay, so Find one one Equals one So find one find two is going to be Yeah, I don't know how to find two yet Uh, but find six and find eight Okay, uh So we we we have we can find the find seven That's not gonna be this one and seven Equal seven okay find four is going to be not this one not this one four Four okay, so we found one. Okay, and seven and we have eight Okay, now find zero is going to be Lee and it's going to be Uh, so we remove okay, uh, where uh six equals find Six Lee and So to find zero we find the six And then we remove the six and then we take the one with one two three four five six Uh, so we say the one that's uh So find zero we take the six. Okay, then we say Remove char And Lee is going to be equal to a filter not equal to Char a Filter not equal to so let's say it'll dig. Yeah, they're not equal to dig filter not equal to Char this is a set of char Set of char like this to Set of char. Okay, so find zero is we take six and then we owe six equals remove char Lee six This is the one that let's just say if you have something called import List we have find right find a case Find and then we say six equals Because it should have a One yeah six segments six Six we just do six equals length On a we owe six of Just a char goes to char Nothing goes to Error not found Zero not found Okay, so we found zero we found one we found Four so how do we find five? Eh, do do do do bcdef So we can we can figure out g Oh, okay. No, so we can figure out a So by finding six in it we can figure out a And then we know which one is b Okay, so let's see find b Let's see find b Is going to be a We don't do it like this find b is equal to where so it's find six So so eight is going to be find eight of lay Six is going to be find Six of lay And then this is a Six a six set so Wait, yeah, because so six is going to be like Right, it's going to be all of them except a Right Yes, sorry. So this is find a actually Find a so to find a we take a eight set Difference with six Now to find b to set Jar we just say find b of list is equal to uh white Where one equals find one Find one Did I actually use no, I don't use find d yet Okay, let's see You see let's come in this is so find b is one and then find one lee and his one set a a where a is equal to find a in leave Okay, so if I know a in b And I know d Okay, so how can I find so I know? So I found zero And I found So if I found zero So zero is going to be you know these right so it's eight a so so to find f Find f is going to be set of jar set Jar find f is equal of lee is equal to a eight set zero Where as zero is equal to find zero of lee And eight is equal to find eight in lee Okay, so then I know f Okay, so an e is a So four is a b e and f right? So Find e is going to be set jar Set jar find e is equal to a lee is equal to Where four is equal to find four in lee So then I know a I know the four and it's going to be e So find four and then minus a b and f right? minus actually just it's just minus one and then minus f So one is equal to find one lee And this is a four set dot so set dot We take away the a and b from four And we take away the a f Okay, so now we know how to find so now we have a b e and f found a b e and f So a b so we can find c and d Eh, let's see a a b d e f So to find nine Find nine lee is equal to set dot unions a a b a b b d e and f right a b d e f where And I already knew how to find d. Oh no a b and d right. Let's see here Find d lee is equal to that was a Where one equals find one lee seven Equals find seven lee find seven lee So this is going to be a I mean, so we're writing a lot of functions, right? A find d is going to be seven set one So we have a b d and a and a a b c d e. Okay, let's have it the other way around Okay, so we have a b d e and f Find the here we have a b d e and f So a b d e and f where A is equal to find so this is going to be some inefficiency here, right? Find nine lee but it's okay a set char to set Char for a is equal to find a lee b is equal to find b lee d is equal to find d lee e is equal to find e lee and f is equal to find F lee So we found Now this is not a car. It's at a chart uh So we found eight We found zero one four six seven eight nine six seven eight nine Okay, so what do we need to find we need to find two two three five Two three and five So two Is okay, so we have a b d e and f uh a b d e and f so we need to c and g a b d and f Okay, so three is a Seven and let's see c is seven So if we take seven So if it takes yeah, we can't take it right good Okay, uh Let's see so if we take eight and uh We already found f right, let's see So we have a and b and d and f a b d e and f So what letters we have to a b c b e f g we need to find c and g so b d e f g So we have b d e f So we have c and g here. We don't know which one it is So okay in nine we have a b d. Oh no, we have e right Uh a b d e f. Yeah, so we already know that one b d e f Uh, so but we don't know which one so we need so we need a So we have find c And then we need a find G Okay, what do we have? Uh, so and we need to say find two find two Lee And we need to find Three so we have four and we need to find five. Okay. Uh, let's see now Uh find a b so c and g now if we had both of these we could just figure it out right away so c And g so this one has so two has both c and g So if I knew if I could find five I would be good, right So zero has both e and g Six has e and g eight has e and g. Yeah Okay, um a b d e f Do-doom-doom-doom two and three and five Let's see. Um, two three and five. That's the ones I need to find two three and five a b c d f Right and it's c and g that I don't know. I don't know c. I don't know g Uh, so see they both have c So this one has c and g This one has c and this one has c Um Okay, so I remove the ones I know. Okay, so if I say so I say find a So find something. Okay, so finally. Okay, so let's see where uh No known so we're gonna say uh fold r Uh, so what's the type of folder again? We always forget Find Equals le so what's the type of folder again? Uh, why are you saying this? Oh, yeah, because it's in the middle of the canonical side of this bucket Ding. Okay. Let's remove this So find so no no knock is a folder. Okay. What is the problem? a All right This is to be find uk Okay, unknown not the united kingdom. Okay, so This one is like the it takes in a Like a list of a and I yeah, okay, so, uh, I'm going to say remove char So folder takes in so it's it's Flip remove char actually And I have the le and I have so these are the ones. Okay, so I Folder are no known. Uh, this is gonna be The 174 9068 Where? Okay, so let's write these so one equals find one le Seven equals find seven le Four equals find Four le Nine equals find nine le Zero equals find Zero le Six equals find Six le Eight equals find nine Find eight le So no known so I remove so the this is Two two three and five So now we have these three. Okay, uh, so We owe known char's we do map Because let's write here first known char's Is so we know a b d e f Now char's is uh the set dot union of a b a b a b d e f a b d e f a b d e f So a is equal to a Find a le B is equal to find b le D is equal to find D le E is equal to find e le f is equal to it's going to be very painful to debug if it doesn't work out, right? Find f le a Okay a b d e f A so we this is these are the known char's So Remove known Removed known is equal to map set a Known char's of two three and five So this is then going to be the set, right? A so there's no so there's no no a so there's a c and g and then there's gonna be as C and there's gonna be a c All right, so I can All right, so b d e f B so a b d e f so I know those right so this one b d e f and b a b d e f Okay, uh, so I can sort these on length Sort by compare on length Okay, so now it's going to be c c c g So find C and g All right, this is actually going to return Up to a pair right so c comma g So I have removed known so this is going to be A c and then whatever And then c g And then this is set g minus Nice, so this is c g without g Okay, uh, so find c is the first of find c and g G and find G is equal to second Okay, and then we have All the letters right we We can uh now we now we know all the letters Doing bling bling bling bling bling Okay, and I think we should like run this on something right Um, so okay, let's write now find two then right they Find two that's gonna be Set that unions Oh, how do we write two we said a c d f g a c d f g and find three is set that unions of a b c d f a b c d oh no a b c d f And Find five of where is the five b c d e f b c d e f Where and then we just say like this a b d f And we can actually just copy you have it the whole thing a b Uh c equals find c le And we don't need the e a b c a we don't need the b actually And we a the it's a c d f And g equals Find g okay, uh Same here Where and then this is b b equals find b le b c d f no g And find five is b c d e f So we do like this so b c d e f find e le b c d e f right Okay, so Now we have to take So now we found all the numbers right a we found zero one two three four five six seven eight and nine So now we have to define the Reverse look up Look up A char look up. Okay, which is going to be equal to um So we're taking the Le and this is going to give us a map from string to hint actually a char look up set of char to map string and char look up le equals a Where A n zero equals find zero Le and we just find all the numbers and one equals find One le and two equals find two le and three equals find three le Okay, we can actually do this a lot nicer If we change it now, okay, because we need all the functions Infants, okay. Let's just write like this. We can clean it up And five equals find five le and six equals find six le this might be actually super slow as well I don't know and seven equals find seven le Uh, no, let's actually do it different way, right? Let's have this be like a list of uh a Letter it's equal. So it's find zero find one find two find three Find four find five find six Find seven find eight find nine Well zero one two three four five six seven eight nine Now uh apple letters It's gonna be um It's gonna be map Uh, and then this is gonna be an f2 F le Apple Uh, and this is gonna be on the letters Digits actually, this is the digits Digits can you dig it? Uh, so then we have and then this is gonna be the Digit funds and this is gonna be digits Digit funds. So we have um That's actually we we're gonna sip zero With this fun and then we're gonna say i comma f and this is gonna be uh Let's do it the different way. So we sip the digit funds with zero to like this And this is gonna be f comma le comma i Fun i okay, so now we have the map string to int We actually have the map Set char to int Let me just inline this Okay, now let's check on this read input two um print Let's do print dot char lookup What is it gonna be on this one is uh syntax error? Okay Yeah, I know this is like some weird thing that it does sometimes Uh, right Import data dot map Map import data dot map Import qualified Data dot map as m Yes, okay, this is actually gonna be map A map dot from list Something like this And what is this complaining about? No, right? This is Yeah, because I said I want to say map here And it's going to tell me that So you can use sip with sip with ding ding ding sip with takes an list uh, uh, oh great f I think it's like this. Okay. Now char lookup. So this is uh Kine match type. Uh, okay. So read input two takes an list list of such chars and strings Uh Okay, let's just uh print This What is it saying now uh read input two i o list of set chars Now if I do fst of Then now Why is it complaining here? This whole has a type of Okay, and let's say map fst char lookup All right, so find cng he yes This one is not in scope Do do do ding ding ding find g find so did I have find cng? Yeah, because I want to remove C non exhaustive patterns in res Line 133 Okay, so I have six and I Okay, okay, so Read input two Let's see here. Um, what does it say? Is it like not it's failing for So a b d e f g a b d e f g So for the first one, let's see What was it for the first one So b e is the first one yes Let's See so I remove Wait, okay, so I removed the last one Okay, yeah, this makes sense right I can't just uh So what was our what was our uh What was our argument there again? What was the argument for find six so six? six is like if we um If we if we remove eight and we remove a and b it should be unique, right? So let's uh It should have the unique length So it was like this right we removed to the last one every remote b and then this one should be Of length five right and this one should be Five equal Five equals length set that size What are you complaining about a Couldn't oh no All right, so find six. I think we have to just give it a type There's some find six set So let's set of jar to set of jar Okay, and now let's remove first show here This is probably not going to be the first one non exhaustive patterns in ccg Okay, but this is like very late right a non exhaustive patterns in ccg Uh, let's see map set known char. All right So let's see here was two three in five Eight dollar Trace show id Okay, and it's not what doesn't want that Okay, because I removed it. Okay, let's see what two three and five here is a Oh, okay So I removed one seven four and nine from that list char I'll remove char doesn't do that right it Uh, it doesn't um, so this one should be filter So, okay, so we we don't get that. Yeah, okay, so we get the uh D And we get the l And this is filter uh not equal to D Yeah, so we actually just get like this. Let me don't flip it I think it's like this Is it? No, okay. Uh, let's see Let's just do trace show uh le Filter and not equal one a Lee what does that give us? We take the list and we remove the one that's one Yeah, okay that one works a but So we remove that one and the seven and the four Okay, let's trace show a 9 0 6 8 Let's do that and let's also show two three and five Okay, so we have a a c d e f g a c d Oh a b d e a d c d a f g. Okay Well, thanks for the sub I can't pronounce your name though you will have to Pop into chat and tell us how to say it Because I can't read the I I know who you are though You're from twitter, right? But I just I know your I know your letters, but I don't know you I I don't know how to say it. It's a bit funny, right? Okay, um Oh my god Baka streamer. Oh, yeah nice Let's see Baka streamer Nice Oh, I said this would be rough, right? Let's see Let's also Let's say Let's show a and b Do do do do do do do do Oh, okay. So a is like two characters and b is uh B is in line one empty set. That's not good. So a is eight Without six Okay, so there are there are issues Somewhere here, okay trace show id So now we're looking at a and a should be a single Character set And it's not right. It's it's okay eight without six so it's probably because Either eight or six is okay. Um, right, okay. So how did we find eight? eight should be A should be a b c d e f g Right a b c d e f g Okay, and then uh six, maybe maybe six is written differently No, it's a It's like this exactly six so in our Canonical way, we we did it in a weird way. Okay um Right, so we actually we are trying to find a so a it should be so one should be a and b That's um So this should be this is from the first example, right? Okay, so eight is a okay Right, so we take eight And we remove one so okay, so what do we find out the one was? Let I think maybe our six here is wrong a Right, I didn't add So I filtered the res out So this should be res Um, but I have to add something back, right? So I think I find out the side it should be like this A set one Because I actually yeah, so I think that's the issue now we're printing the eight Oh, so now we get b And we get e as the first one Let's actually run it on a Not the read input example But let's say print Yeah, um, yeah, so let's do it that way, right? So read input example, but we are going to Add the first one here actually and let's So this should be all x and this is a one line sample And we go back and we say read input all x here. So then Like a should be so one should be a b, right? Yeah, so so we found a and we found the right b Okay, now let's uh, let's see what we what else we have a b No, we haven't found see we are in the process of finding c at d e and f So this should be from list a from list b from list d from least e and from least So we have a and b and we have d and then f is wrong and then And then so e is e and f and then we have g for some reason So how do we find e? that is four Without one without f, right? So an f Was a so let's find zero So I think I think I think zero is the one that's probably wrong Nice to be able to test it like that, right? So find zero a Yeah, exactly It's going to be a res It's the same as before, right? So it's going to be res equals filter six equals dot length Of uh, so what is this without six? Okay, so we remove Char sik, right? This should be removed digit Okay Not right. This should be filter Not equal to six only Let's see now it should be a bd a b d e f g Yeah, and I think it's because like we remove a Let's print out here where we get Prey show res equals whatever this is Let's let's have this as res And then just say, you know filter And then we just say like this And so we we find we remove six from the list and then we have a res and let's say trace show A zero comma res Let's just see what it says Oh non-exhaustive patterns in res Okay, that's that's the shoe probably trace show But let's print six first a trace show six a Okay, yeah, so we do like this trace show six Six now let's figure out how six is printed b c d e f g and how did we say the count of six was b c d e f g exactly Okay, uh b c d e f g And there's no other that just has one missing, right? Maybe this is set it up size Maybe it's some funny interaction there Six from this b c d e f g Okay, let's just see What the list here is trace show id So we say of a b a b d a b c d e g a b c d e f and a b Okay, so we have Two of size Six now which one Are we missing six seven eight What is this? Oh nine. Okay, so nine is not okay All right Yeah, so I was thinking of nine like, you know without the lower line Okay, that changes things Okay, so we can find eight and then a Okay, so we have to find You can find e or like yeah that one Okay, that changes things So um Okay, so now we have to kind of rethink all of it Okay, we can find eight then okay, so then we say a Find six and nine is equal to So we have find six and nine a That is filter length is equal to five of set size of the image Okay, six and nine right So Okay, so find six Where six and nine equals find six and nine Okay Uh Right night. Yeah, so this one is find six and nine. Okay, so we have here One and then the rest. Okay. We take the in it dollar Okay, so find so no we're we're gonna do this all at once. Okay find six and nine Find six and nine is going to take a list of set char's and return a set of char Instead of char. Okay Find six is then just going to be the same find six equals first of find Six and nine and find nine is equal to the second find six and nine Okay, so find six and nine where okay, so now we filter So this is going to be s or s or nine So this is going to be Uh, because we we're using all the letters here. This is going to be x and y equals to filter five is equal to the set size Right, that's true, right zero and oh zero and so zero and six And nine are actually all the same size So this one is so the c also here. So a b c d e f Okay, and a b c d e f Okay, so I know how to find zero right because um Wait, so do we know how to find zero? Uh, no we found f. We don't know f yet At that point in time Okay, so I know one right so six is going to be the one of these three um That shrinks when I do one. Okay So find six. So this is going to be zero and six and nine so zero and six and nine set char And then this is going to be yeah, we're going to do these later Okay, where x y and uh said We're just going to get the ones that are of length six of the uh rest Okay now So, uh, so one of them will decrease if we remove the set one and that's the number six So, okay if uh So let's find the six Is equal to if a x set a one set set dot size Is less than six Then x else if Same right, it's just a decision tree if uh y remove is less than six then it's Then y else said Okay, so we found six Okay, uh, then we can find a so we have six So six Okay Okay, uh, what did I have yeah, so we had to find six. Okay, so, uh Six and then r is going to be the rest x y instead then and this is y x x comma said said x comma y So we found a x prime y prime So one of these are is going to be a zero and six and Okay, we found six. So one of x prime and y prime is going to be Yeah So we we already found a and B Okay, actually we can just see which ones don't have a so how do we find a again? Is that just lucky We find a you know, we we use six to find it. So that uh that one was uh And then we use yeah, okay So we can't really use the characters here Now, okay, so let's see So if I remove And let's see if I can rewrite this No, okay, just didn't so if I uh, so I have the other ones Ding ding ding ding ding ding so I found six How can I find zero which one do I have? So I have six and seven and I have Okay, right. So if I have four so the one that The one that's lesser if I have four Is going to be four defined for Right, so the one Let's let's have this as a Lee and this is Lee and then one Is equal to find one a Lee Lee Okay, the one that shrinks if you remove one, that's the six. No wait That because that that one only shrinks by one, right? Well the other ones The set size is equal to five That one only shrinks by one, right? Okay, so if I remove the four Then zero shrinks by Three while nine shrinks by four So then we have a zero And nine so okay, this is like, okay, so if set that size a x set minus four So, okay, if I if I have a if I have a Nine And so it says five and it shrinks by It should shrink by four So if I if you have this is equal to two Then a Then it's a y comma x else x comma y Okay, I think we fixed it Okay, and what if we just Kind of combine all of these find nums We have a one four seven And then the rest Okay, so this is gonna be rest and Not these So I have So at this point I have a one four a six seven nine And I know that I have eight as well eight is equal to um So this will be probably much faster. We just do it all at once right eight is going to be the last of the list So so it has six seven eight nine So four on four six seven eight nine, okay Yeah I mean this one is like, I don't know if this is a lot of haskell programming This is more like a We're just solving this problem right and we're we're using haskell, but there's a lot of Hey We're doing a lot of cases now and we're trying to do it like all at once It should be fast, but yeah But yeah, we'll get to the stream. It's always fun to get more people in here Okay, so we found six seven zero six and nine We have one four. So we need We need we need two We need three one two three four five Six seven eight nine uh So we have zero as well zero Okay, um So I can I can actually figure out. We can actually figure out our F by removing zero from nine. So f is equal to eight Set is zero Okay, uh Now so we need two three and five. Okay. Uh, so we have So all of those have Let me see. Uh, let's see. We have four. Can we make something if we add a letter to four? Uh, okay, we have one Okay, we have seven If we add a letter to seven We need to add like the the bottom most we need to add c to seven To get three No No, no, no, sorry And that's not correct. Okay. Uh, but we have nine. Uh, let's see Okay, let's see we have uh We have nine So nine minus a is um Right, okay, so So, all right, so so a so eight minus six is a a is equal to eight set dot Six Okay, uh And and five Is nine without a With a new nine. So five is equal to So nine set dot Yeah, it is. This is pretty pretty Rough I think right Okay, so then we have a zero one four five six But we need two and three So two is uh, okay, so three So we if we if we add a Well, thanks for the sub by the way I like god see I think No, not the sub but the follow but I need one more follow that I have 200 followers That's pretty nice So five Uh That's nine minus a Right, but nine minus e Is three So can we find three somehow? Three is equal to nine Set Three no three is a with so nine Minus e so how do we find e? to good to good to do so which ones have e a So we have five five has e Okay, and we can move no we don't have three okay, so Five minus one is d f and c How does that help doesn't really help right? Then we know Five minus one is no that's d e f and c right And that without so five minus seven It's actually e f and c right so if we remove so we have five and remove seven we have e f and c So let's just write that e f c equals a e f c equals a five set seven okay, and so e c equals a e f c set A f right we already found f Then e Uh, so which character has e but not Which character has this one? But not this one. I don't know. I don't think so we have not yet two. Okay, so e is going to be equal to Uh, e is going to be equal to e c set two So now we don't have we don't have two So if you find two we've got it right the two is equal to Uh Oh, but if we oh, no, no, no c we you know, we we have three. Okay Because this one is f so wait so we have four I think we can get e another way Let me see So we have a Five right now. So we have a We have nine and if we remove four we have We have if you're here, we have nine every remove four we have d and c Uh, let me see So we have nine remove four we have a and g and then we remove Seven we have the lowest one Which is c So c is equal to nine a set dot Without a seven A set dot without four Okay, so e is equal to e f c a set You see set a e now c is at f set minus c Okay, so we have And then we have three So we have zero one four one three. So we need two Now two Two here is going to be E So we have oh we found three already. Yes Because three is just nine without this we have the three. Okay How do we get the two? Right So we get the two Okay, so this one was the e That we just found right so the e and b do we know b So two Is equal to eight set minus minus b set minus minus a And we know that b is equal to one set minus one is eight Okay, so this one is just going to be and so we found kind of all the nums at once here Without all of the other ones. So let's check Find nums map. Okay. So now I I have this char lookup function So this is going to be a map so find nums. Let's just say map Set char int And then it's going to be map.from list Dollar sip Zero and then we have zero one two three four five Six seven eight. Okay. Let's uh, let's uh move everything else that we did We just undo if it doesn't work, right? Okay, and we don't care about these anymore So this is all gone Okay, so here we're just going to say So a b now let's Let's trace show some stuff trace show One two three four five six seven eight As zero one two three four five six seven eight Nine right Now let's say Can we do find nums here? Does it fail anywhere? So a b is one a b c d e f is okay. So so it definitely says something right? one Two three four Oh, it doesn't have five in the list Ding ding ding ding ding one two three one two three four one two three four five Six seven eight nine So it has zero one two three four. There's no five seven eight nine Let's see one two three four five six seven eight nine ten exactly Oh, we're looking at this one one two three four five six seven eight nine ten This one it shouldn't break this way, right? Uh, wait, is it maybe what am I printing here? find nums trace show a b b c d e f g let's see c d f p e okay, so we're getting the wrong ones Okay, so one is correct and four is correct and seven is correct, right? That's definitely One is correct four seven because right and yeah, okay that makes sense But five is not correct, right? So because it's saying so nine so c e f So what is nine here? We're getting it wrong somehow It still should show up in this list though. So okay, so a b Is one Yeah A b d is seven. Yeah a b e f is four. Yeah a b e f yes Okay, a c d f g a c d f g. Yes a b c d f is three a b c d f. Yeah b c d e f is five b c d e b c d e f is five. Yeah a b c d e f is nine a b c d e f. Yeah And a b c d e g is zero Hey a a b c a a b c d e g is Zero b c d e f g is six b c d e f g Yes Okay, so, uh That's right. So if I remove one from here, which is a b. Let's be okay. Let's let's just see what it says Drink ding ding ding ding ding. So these are a one two three four five six. Okay Let's trace show this trace show ID first of all a b c d e a b c d e f. Yes a b c d e f g a b c d e f g. Yes at six and a b c d e g. That's five a b No a b c d e g. That should be Yeah, so we have a we have the right ones in that one Okay So if I remove a b from this one it should be So remove a b from the the set size should be four Right. Okay. If I remove a b from this one the set size should be four So b c d e f g is the only one where if I remove a b the set size should be five Okay, so What do I get here? Trace show ID. Maybe it's not the six that I'm getting more. So b c d e f g is the six b c d e f g. Okay. Okay. So the six is correct Now a So it's the zero and the nine Okay, so if I if I have the nine Nine and I remove the four it should be two Okay Oh, if this is not right, so this would be x prime Then there should be y prime and x prime and y prime x prime Okay, that was the issue so So we have a b one zero a b c d e g a b c d e g that was nine Oh a b c d e g is nine but that should be d e f right a b c d e g. Oh It's not good a b c d e g Which one is this a trace show id so we okay. We get the a b c d e f So this these are a okay x y z y x z z works y So what we're seeing here is a If so if we remove four and that's two trace show id Am I getting these two wrong? I think so, right a a b c d e f a b c d e g So a b c d e f that should be nine, right? Okay, so if I take so I have x prime a So that's one of the a Okay, and I remove four Let's trace show that right trace show id dollar on this whole thing Okay, so if I remove And what was this again? Okay, so I got b c d e f g. That's the six Which was correct, but the nine here So four what is four e a f b? So remove e a f b as I get c and d here, right? All right, this should be one and then seven and then four a b c d e f is nine a b c d f. Yeah, okay This one's correct a b c d e g. That's a zero. Yes a b c d f is a three a b c a b c d f. Yes, so we have a b d a b e f. Yeah b c d e f is the five b c d f. Yes b c d. Yeah, we already kind of have one and yeah, okay I think we finally got it So now let's remove all these traces here And Because we don't need them anymore Now it's complaining because I want me to use a Guards So how do I do that again? Right? Is it like this? Set size equals something like this. I think it's like this. So maybe like this Okay, now I have the guards It doesn't complain anymore Okay, now I know what each of the letters are great Okay, so this this is five three five three Okay, and Okay, now let's do this, right? Okay, so read input. So task two task two, okay, we're taking a list of list of Whatever read input gives right? and We don't need this anymore So whatever read input two gives so a function that takes in this And okay, we're actually going to map on both of them a map sort We don't need to Sort them. Why are we sorting the words of the rest? We just want to have map set dot from list here Okay, now we then we have find nums now task two takes in a list of set char and Another list of set char And it should return an int. Okay Task two Equal sum of map task two prime over Yeah, okay, just like this And what are you complaining about now? Perhaps uh Oh, yeah, okay. I need that And the map task two prime where task two prime is like key and digits equals Digs let's just say okay, so I knew I do a A where f equals find num key A so I have a Decode is find num key and then I do a Map And then it's map dot bang so we have a Decode map and then we have a digs So this is the find nums So this one gives us a Let's actually just do it like this first list of list of Ints map Map task two something like that wait, um, and then we wait. Let me use it. We'll be like, um Okay, so what do we do now? We do not print we do map task two and now it's complaining read input Two is because this one doesn't return this it returns set chart Okay, so now we're gonna run it on the example Oh Map given key is not an element in the map Oh trace show ready Okay, a b c d e f g b c d e f b c d e f g b c e g So that's that's eight and then this one is going to be the four Uh, what is it being what's happening? So eight three nine four Work for the first one nine seven eight one works One one nine seven works nine three six one works Four eight seven three eight four one eight four five four eight a And then it should be one six two five Whatever I do. I've got a question Maybe it I just see which one it fails for Ding ding ding ding ding ding ding ding Uh, so four five four eight works And it fails for two so eight seven one seven four three one five What why does it fail for two? What's our definition of two wrong? Let's say Could be right II All right, so we removed the Right, we removed the wrong data. So we're gonna remove the So two is going to be removing the b and the e Not the a So now it should be like this Okay So we just got the wrong two example Okay, now it doesn't crash for the two Okay, uh, now we don't need the tray And And we don't need the trace here either. Um, but how do we make these into? Numbers And okay, then let's just say so Thou thousand hundred Ta u equals this So it's gonna be so times a thousand this is very dirty, but yeah Who times a hundred Plus t times 10 Less you All right And then we take the a we want just some So for the example, we got six one two two nine We're still getting some pretty shorty. Uh, let's move Uh Six one two two nine. Okay now Let's just do for input One zero four zero four two nine We finally did it and it only took us two Hours to do part two We were like 18 minutes with part one Uh Yeah, that was Quite a lot, right? I mean We ended up with a solution that's quite fast But like it's because we're just doing a lot of set manipulations And I think like we went overboard in the beginning, right with a find a find zero blah blah blah we like we just We we just figured it out Like we could all condensing it to one function But that was like after we were had worked with it for a while Uh That's when we figured it out Like how we could figure it out, but also like the that nine screwed up us up, right? That was uh, we did not expect it. Okay. I think yeah, it's running Quite fast, right? It's like 10 milliseconds and it's just a bunch of set manipulation. I don't know if I don't think we can do this any faster Um, I mean we ended up with quite a lot of uh stuff. Yeah Okay Uh, I'm going to call it quits for today. It was Quite a marathon actually But I'm glad we did it. Uh, let's add this code get status get add a d8.hs and example and input Okay, I pushed it Yeah, thanks for tuning in but like yeah, it was rough today We like at the end we ended up like it's like, you know to solve part two, right? It was Not a lot of code, right? But uh, it was a lot of tricky things and there's no I don't think there's a good way to brute forces or anything like that Uh, okay. That's enough for today. Thanks For tuning in make sure to follow If you want notifications when I go live next Um, and I hope it didn't take too long today. Even though it was a bit much um I think we learned a lot All right, we didn't learn anything really like we we really just had to stare at this and figured out how to do it and like Because you know I write Nines Like this right That screwed me up All right, thanks And I'll be back tomorrow at seven And hopefully it's not as long because I have other stuff to get done And and uh, yeah, check out the youtube videos, right? So I think it's linked down below where I have I just upload every day, right? So if you want to Watch previous days and you can check them out, but they they don't appear until like 24 hours later because there's an embargo From twitch, but yeah, all right. Thanks for today and uh catch you all Next time All right. Bye. Bye