 All right Welcome back to day two of Admitive Code. Here's my Twitter Here's the code and Look today. We have the keycap So you can see how I type Also my ladder keyboard, so I'm hoping that Because you can see it a typing noise won't be too bad. Otherwise, I'll have to switch back to the More quiet keyboard, but you know That's just how it goes. All right, let's get started with day two of Admitive Code Code.com Haven't looked at it yet, so Oh, you can't hear me. I spent so long tuning it. Okay Yeah, it should be better Let me see Okay, now I should be better, right? Yeah, okay All right, so always some audio issues. I added some compression today and So I should sound even better than yesterday, but you know it It's always hard because like, you know, I thought I had it fixed and then I got up the volume for the intro and then I That was too much apparently. Anyway Let's get started. So we're going to day two. I haven't looked at this yet so But last time we fixed Santa's finances and just great and now we have to Get there from the coastal airport right on to bargain. Okay. So the shop. Oh No, there's something wrong with the computers at the toboggan rental shop Some of the wood okay, right? Okay They created a list Passwords and the corporate password policy when this password set Okay Each line gives the password policy and then the password The password policy indicates the lowest and highest number of times a given letter must appear For the password to be valid, for example, one to three times a means that password must contain a At least one time and at most three times and the example about two passwords for valid The middle password CDFG is not It contains no instances of B but it needs at least one okay the first and Third passwords are valid. All right. So how many passwords are valid according to their policies? Okay, so I guess Let's get started Copy this. We are going to open day two New file Paste the input Save it We're gonna do a little trick called copy paste I've been doing Computer science since Damn since 2012 that's eight years And I tell you it's all about the copy paste So we're gonna take from file Which is our it just reads and then So a new file Okay module main Face it. We don't need it. It was just a read file From file. Okay. So now we're gonna read the file of inputs And then read them so the format is I think it's you know, it's Number dash number Space letter colon space Okay, so how do we do this I think it's easier to split it at first At the yeah, let's just read them read them and we first Read file Okay Okay Pipe that into let's make it. I don't know but it's always good to just Use what you have Let me see We're gonna do JT Day two. I just oh day two And then you're going to run day two We're not using cabal or anything yet because We don't need it Okay, now we need another function. I think it's called span import data.list Yeah, so it just takes in a billion and then Gives you the things that come before that and the things that come after that so So, okay, now we're gonna it's gonna, you know F string to We're just gonna do unit here string to list the strings Okay, F equals yeah, let's split it just split it into a pair first This is so here we're gonna have the yes Where x on y Equals span and then I think import data dot char I think they have a fun where they just call this char Which a let's just do Equals like this span equals S This will actually just return us one thing Let's just see what happens here if I If I do this first See what happens if I run this All right, it splits. I think we need to do I think it splits on the first one that matches. Yeah, see and Then it keeps the rest We're just gonna be bold. We're just gonna assume that it's here So we're gonna just and also we're just yeah, so we're just gonna assume it's there and Then we know that after it is a space. So we're just gonna match on the space as well Yeah, okay, and then we will return X comma Y. All right, great So now we have the password Next up is the policy so Don't need to split up the X and What is it complaining about here? This is gonna be So let's do first words on words or wait, can I just do on words? Love them initially. Let me see. What is what is so on words of this should be It should be you know this thing and then the space and then the letter and then Letter and the colon and then right Probably simplest, right? Yeah, this is easier, right? So now you just get it as a list Column at the end. So here's the This will be See and then the colon and then the empty list And then the pass equals words s Now the policy we want to split into X comma Y so mean and equals so we Span it equals All okay, so I knew we're gonna just return it Let's say we return In comma in so you got a balance return the jar in the string. It's just gonna be Read Here we're gonna have See and now we need the Type applications because we won't do that in thing We don't need it as I keep doing this I keep like thinking I need type applications Cuz I always just want to make it explicit what I'm actually doing But we have the end here so we can just Figure it out right away Right, let's see But this is not doing so All right, wait. No. Oh shit Split on the dash like this Yeah, that was not minus three. That was bad Okay, and now we have to actually solve the same That is another challenge So, okay, so I think the trick Here is that we only have the one character and we can actually break Early Right, so, you know, we actually don't really have to loop over it once And not even the entire thing so we just We just go over it until we Okay, so Yeah, we go over it until we Make sure that it has You know, we only need to look at the characters until we have seen the maximum And if we've seen the maximum We need to see if there's one more. Okay, so Let's do that So so so here we go cross So check It takes the bounds and it will take a Current number of repetitions and the string so far check And what does it return? It returns Check Okay, actually Yeah, me If it's empty Then we just return So if we if we're at the end, there's no more text to say we just check that a Ma less than or equal to so far And so far less than equal to max so that's if we're at the end Check me comma ma So far Case Access, okay, so All right, we need the character also the char here, okay, so Okay, so here we check if X equals equals char Then we check so okay if If so far is less than So we haven't seen too many then we continue Check shorter So if so far, we're gonna just say here So if if so far is less than ma This then we continue check PC so far plus one Incremented and check the rest if it is the case that X equals equals C So if this is the case and It's so it's not less than it must be more than we just you're in false So we don't actually need this check Here Okay, we just need to check it's less if we've seen so if we're at the end We need to check if we've seen enough of them But while we're at it We need to check if we see too many Other one and then here's the otherwise Check PC Check PC PC so far so let's say String takes the string check pass Now we're gonna do some crazy hacking Let me see check pass Equals, okay, so we're gonna we're gonna S So so my I want to I want to kind of Uncurry the whole thing is that even possible or like curried like music GCI He curry He on curry. Yeah, so I think let me see here. What is the type of curry? Uncurry, okay So I think we should swap these two just to be able to do this one simple trick I can only do switch these two So type uncurry check uncurry uncurry check. All right, you see this it takes in the Yeah, this is what we want. So let's wrap this once more. So then we can see that day two T Uncurry dot so this oh no this applied to So if we Flip this and we apply it to zero. Let's see. So check pass is equal to Flip curry dollar uncurry check zero Crazy, right? So true false true Little password is not Fault to false true. How many passwords are valid? We can just count, right? Okay. Let's just So what's the type of sum? Let's just map it So we have the check passes and then we do some after we've Booleans to integers. I think there's a If there is like a nice way to do this but okay, I mean there's a bad way to do this We're not gonna go there Or I'm gonna go. Let's just say Okay Okay, we run it we get to copy this this is a test input, right? Okay, we copied the test input to test input so we can still run that So, you know, I said this would be functional It's actually, you know, this is just a very tight loop this check here It's just a recursive call Calling itself Until it reaches a Boolean. So it's just it's just gonna be a tight loop And that's as functional as anything. You know, I don't have to generate a list and sum over a list or whatever. It's okay Okay Get the input. You're ready 600. Too good to be true, right? Okay, that was right. Very precise number, but okay We did part one We got three stars already Let's see how part two is Part two is usually like either it's easier because you kind of You wrote the code so that, you know, the additional work is just very trivial or You literally have to rewrite the entire thing Because it has some weird stuff that you just didn't think about so let's see here. Yeah like this Okay, okay, so we validated them, but they weren't correct Each policy actually describes two positions In the password where one wins the first character or two wins the second character and so on Be careful to a bargain corporate policy of no concept of index zero Exactly one of these positions must contain the given letter other What? Okay, so exactly one so we just look up both and Okay, okay Check pass to this is a string. So here We say check pass to Where we just apply our function to kind of parse it into the problem. So here's this is gonna be the path It's gonna be the P1 P2 Char equals This f of s This function here should be named. Okay, this is they say it's not not index zero Okay, so we just save P1 minus one if this is C on that here we want to want to do like a Nor but I don't think we have that basic operation Do we though? One of them we want an X or right? How does exclusive or work again? X or X or a false false Okay, I think a X or a false false equals This is exclusive work So we just say here This is equal to C X or so what does it say for our testing foot? This is still check fast one check pass to negative index They should be P2 minus one two for the five So Does the one match? Yeah, there's always supposed to be one valid one And that's the first one. Let's just Let's just make sure that we're actually Yeah, so it's the first one and it says that the 245 pass rates valid for the second one All right, we done did it again. So now we have four gold stars and Yeah Didn't take long this time What 35 minutes even quicker than The first one. I think I talked more in the first one, but it was also like It was a harder problem In some sense and I think this is pretty fast. I mean, we're not even We're not even doing anything. I mean the only only thing that we're doing is I mean the only kind of optimization we did was This year that we bail out early 21 oh shit, it's like yeah, sometimes 10 sometimes I think it's mostly just like file IO bound. Anyway, 10 milliseconds to 21. Well, he's having a sense It's not a lot All right, I think yeah status No, no, we don't want Okay, we actually have a good This all right, yeah, so That's all for today, I guess Yeah, these will probably become More fun as the challenge increases But you know, I think I think I mean in this this part was mostly the complexity was like the hardest part was parsing the format And then, you know, we even even messed around it spent some time doing this flip flip on curry thing Which we did not have to do so. Yeah Okay So that's it for today. See you all again for day three tomorrow and So I have a YouTube channel where I'm uploading these videos So you want to go check out previous days. Maybe you missed them. You can go there Yeah, like and subscribe I just like doing these So fun and it's a it's a nice Nice playlist. I think. Oh, no It's not actually showing my What the current song is right? Let me see I had a Let me see how it works It seems like it's stopped updating some point Okay Yeah, I think it's because I opened Spotify on one desktop and then One like what that that's about like 4k resolution and then the other one has All right. So yeah, check out my YouTube channel if you want to see previous days and Stay tuned for more Tomorrow, I think it's gonna get even tougher. So All right, enjoy