 All right, welcome to day three of Android of code. I wonder what we're gonna do today. I changed the stream up a bit, moved the keyboard around. People were saying it was too disjoint when it was up above, so. Now it's closer, it's good. The new thing also, we're gonna have the chat be displayed on stream itself. Now I haven't tried it before, so. I don't even know if it works, but it's supposed to work, so. Might as well try, right? All right, let's look at today's task. Do, do, do, do, do, do, do, do, do, do, do. Boom, boom, boom. All right, task three, day three, to bug on trajectory. Okay, there's very minimal searing on the areas. Let's see, due to local geology, trees in the area only grow on the exact integer coordinates in the grid, cool. Okay, okay, so it repeats. Okay, yeah, all right, so this is the input and then it repeats to the right. Okay, yeah, so we have a map and then the map repeats. We start on the top left corner and we need to reach the bottom. Okay, so here we would just go here and here and here, okay. And the bottom is on your map. The toboggan can only follow specific slopes. Okay, that prefers irrational numbers. Start by counting all the trees you would encounter for the slope. Wait, okay, so start by counting all the trees you would encounter for the slope right three down one. From your starting position at the top left, check that the best unit that is right three. Okay, down one from there, you can move on the map. If the locations you check in the above, except marked with the O where there was an open square. Okay, so we go, so zero, one, two, three, and zero, one, two, three. Let's go down one and right three, okay. The axle was a tree. An example traversing the map using this slope would cost you to encounter seven trees starting at the top left corner by following the slope of right three and down one. How many trees would you encounter? Okay, this seems a lot more work than, oh, we got our first chat message happening. All right, so this seems a lot more complex on first glance than the other one. I mean, it's a lot more real world, but the other ones were like data manipulation things. But this time it's more like we have to look at coordinates and stuff, okay. Let's just try it out. We just take the demo input and we open a bit of code. And we already made a new directory, so let's go into day three. Make there, do we have a directory touch day three dot HS? Let's start day three. Let's start day three. Module, main, where? Main, here goes Webster, Ellen, hello. And let's create new file called test input. Here we paste the input and then we will read this input. Let's just try to not get input file. Let's pass to IO list of strings, right? Yet, input, this is just read file, right? Is that half of read file? Oh yeah, this is just unlines over read file. So we split it into strings, pretty easy. And then let's just say, yet, input, test input, type that to print. Let's just see if we managed to read it correctly. We say gtd3.hs, oh, day three. And then we will execute it. Okay, so we got the input. Now let's think about the problem. You can see it here, right? I'm a bit in the way, but that's okay. So we will follow a slope down and we're supposed to count all the trees you would encounter for the slope, right? Three down one. And then the pattern repeats itself. Okay, so in Haskell we have this function called repeat, wrong one, gti t repeat. We have even cycle, which if you say take five of the list, if we cycle the list one, two, three, and we take five of it, it just repeats itself again and again and again. So we will to encode this repetition because we're in a lazy language, we can actually just cycle. Instead of even, you know, we don't even have to like modular calculations, we can just literally cycle the lists. Less of that aim. So cycle, all cycle is just map cycle. We're going to cycle all of them. And then we start at the top. I'm just going to close this. This is another project I've been working on. Save the changes. Yeah. So we're going to go down, right? Down one, right? Three, one, down one, right? Three, down one, right? Three, down one, right? Three, down one, right? So, okay. What is the pattern? So I, let's say it's okay. So we have, let's look at it as coordinates, i, j, right? And I will be zero. I was first zero, then was three. That's how it's like. Yeah. So first it's okay. Okay. We don't even, we don't check the first one. Okay. So the first one is always, yeah. So we always start here and then we go zero, one, two, three. Yeah. Okay. So it's three and then it's three, four, four, four, five, six. Five, three, six, nine, so on. Okay. And then you always go down one. So, okay. And how long is the input? So we're essentially asking just take every third element of the list starting from three. Is that correct? Zero, one, two, three. Zero, one, two, three. Zero, five, six, seven, eight, nine. So we're taking the third. So it's first is plus three, then it's plus three. Yeah. So it's every third element, right? Yeah. So if you start, if you're taking the index from one, because this is like the fourth element, right? Yeah. And this is the fifth, five, six, seventh element. So we deduct one. Okay. So anyway, zero, three, six, nine. Now, what is the length here? Let's load this. Get the test input. And let's do print the length of it. So how many lines is it? And how long are the lines? Okay. So it's 11 and 11 is not a multiple of, it's not a multiple of nine, multiple of three, right? So this will be zero, three, six, nine. And then, you know, 10, 11. The next one should be 12, but it will be 12 mod 11. So there'll be one, four. So can I just generate list list? Okay. Let's just say take every third element. Okay. How do we do that? Take every third. So what we want every third to do is that we want every third. So we want to take every third of, you know, one of zero, 10 to be three, six, nine. Okay. So take every third. Okay. Of access equals. So okay. So we drop three access. Let's reload it. And let's say take every third of one, two, three, four, five. One, two, three, four, five. Let's just do one, two, eleven. I guess it's four first. Okay. So we want to, yeah. We started at one. Okay. So we want to drop three. Okay. So take every third. We'll operate on infinite lists. Right. Okay. Can I like do this code completion or something? Nice. Okay. So it will be a where. So we'll be dropped. So we drop to access equal drop to this will be drop X drop to access. So we guess let's say this will be why and this will be wise. And this is the first element after we drop two. And then we will keep taking every third. Let's reload. Three, six, nine. What if we take ten? Ten. Take every third. And now we just want all the integers. Three, six, nine, 12, 15, 18, 21. Okay. And then we're going to map. We are in English mode. We're going to map mod 11. This will be like this mod 11. Three, six, nine, one, four, seven, ten, two, five, eight. So these are precisely the indexes that we want. So chords. We don't actually need to cycle them. Let's just inefficient. So chords. That's going to be a little spin. Coords is going to be take every third. So, okay. So here we will say, so let's generalize this, right? So it's going to be take every n. We're going to int. And we will drop ten. Take every n. And then I like having a list here. Take every n. Because, you know, it's definitely going to be the case that for task two, part two of this problem, we're going to have to do something else and write three down one, right? So let's just prepare for that right now. Take every n two. So this will be n minus one. Take every third will be take every n. So we start with one, take every n. And then, yeah, so this is exactly what we want. Okay. And then, so now we have an infinite list of coordinates. And now we want to take the hookup input. So it takes a list of strings in the lines. It takes a list of coordinates. And it returns list of values at that point. Lockup in input. So if we don't have any more input, we don't care about the coordinates. And we will say empty list, look up in input X axis. So if we have a line and we want, so then we have the chord here. That is going to be a line. I'm going to call this a line and a line. It's because it's going to be lines of input. And we're going to do L and C. You know, actually, you know, so we're not, we haven't. So here we map the mod over. So we're going to do line, C, mod, module, the length of L and concatenate it to look up input. Okay, let's look it up. Let's see here. Okay, so let's do this. Do TI, test input. There's going to go test input. We're going to print. We're going to apply look up in input to the test input in the chords. We have result, run main. Okay, so first one was supposed to be, oh, okay. Yeah, we don't actually, we drop the first line as well. Could we start going down? So the chords here are always going to be zero. And then, all right, three, zero load, run main again. So first we don't hit, so first it's going to be zero. And then it says period. Let's print the chords. Zero, three, six, nine. Okay, so this one is going to be zero. Zero, zero, right? Let's print the, okay, yeah. So this is the input, right? Test input. So first one should be nothing. Second one should be, so I have one. That is this line, right? And so if we look up, so we look up here, we look up three. Okay, but are they, no, so this is zero, one, two, three, yeah? If we look up four, we would get the three, right? Yeah. Okay, and then, so okay, so that's this one. And then we go one, three, four, five, six. We hit this tree. So let's look up line two. So that's zero, one, two, three, four, five, six, right? That's a tree. Okay, but look up in input, run, give us something else, right? That gives us dot for the second one. Oh no, yeah, okay, yeah. The first one here is going to be the first one, right? This, and then it's going to be the circle. Yeah, so it's first going to be circle. And then x, yeah. So it's dot, dot, x, dot, x, x, dot, x, and then x, x, yeah, okay. All right, I think we got this one. So now we define an easy function is tree char to blue is tree equals. So this is a tree. Anything else is not a tree. So we look up in input. We filter is tree. And then we see how many that is seven. Good. Now let's get the real puzzle input. Okay. So here, new file, input. And let's see. Okay. And we have the test input. Let's see what happens. We will take it. Let's just go here. Get input. Input. Pipe it a count. Let's just write this as a function. Count print count trees test. And then we say print dot count trees. I think I should be able to, like, surely I don't have to press it with my mouse. Anyway, this should be, let's just change it to be the piped one. I don't know. Then I don't have to give names to things, you know, just, oops. Run it. Reload it. Run main. 178. Let's see if that's correct. We got the first one. All right. Part two. If for, so, yeah, okay. Terminal number, if for each of the following slows, you start at the top of the corner, traverse them up all the way to the bottom. Okay. Yeah, this is exactly what we anticipated, right? So, count trees. Let's change that, right? Count trees takes in an int and an int. Count trees gen. And this is going to be, right? And this is going to be down. Okay. So we still do the length filter history. So, cohorts, we need to generalize cohorts. Cohorts is going to be, cohorts is going to be gen, cohorts, gen. So that's where we need to actually put the right, the right and the down, right? Is that so? Here we say, cohorts, cohorts, see. Cohorts, see. Cohorts, gen, see. Okay. So it always starts with a zero. Well, this is going to be right and it's going to be down. So here we say, right? And so, so my question is right, two, right one down two, because you produce two trees. So right one down two. One, okay. Right one down two. Right one down two. Right one. Two. Right one on two. Okay, that goes down only one. So that goes down, right? Yeah, that goes right once. But then down two. So it doesn't go right one, right one. So we have to change that for that one. Okay, but we want, right one down two. So you want to take every other, you want to take every other element in this list. Take every and, take every and down. That's just job zero, right? That's possible. Yeah, so we can just drop take every and down. But we want it to, we want it to, we want to divide by, by the, we want to multiply. Wait, I'm thinking about a bit. So we're multiple. So we're taking every and down. So this will work for all the other ones, right? But let's see here. So cases equals, what are the cases here? So it's right one down one. This is going to be, and then it's going to be, oops, this is how you write it in Haskell. Then we're going to go three, one, five, one. Three, one, five, one, seven, one. And then one, two, cases equals, there's a list of int comma int. And the input will always say the same, but the countries will change. So we will change this into like this. Because then we can just map over the cases. Okay. So let's try it out. Get input, test input. Okay. So yeah, I mean, this is not the best spot. It's okay. Okay. And then then we will just say print, map, count trees. Okay. So we can just do it directly. Print dot map, count trees, gen. Okay. So, okay, let's just, let's just not do it this fancy. Let's just say, yeah, I get input, test input. And then we will print, map, count trees, gen. You see, because otherwise like the, we will have to flip and flip and flip and flip, which is going to be too much flipping. So we map it over the input over the cases. Let's see here. So 27342. So it just works for the second one. Okay. I think it's, I think it's okay because it's one. We don't, I think we, we'd have to like divide by right. Let's just go here, print product, 336. Let's just run it on the real input and just see if it works. I think it should. I think we would have to actually generalize this one properly. This take every end thing. I think you would have to generalize it properly. But because the only case where it's not one right is going to be one. It kind of all works out anyway. So I think let's just, yeah. So let's just try it out, you know, see, see if it works. And if it does, you know, we don't have to do anything else. This is a nice thing about having an Oracle like we have here. You know, we can just actually check if we got it right. I mean, and we got it right according to the tests here. Let's see. That's not the answer, right? Yeah, I think this is because we didn't generalize properly. Let's go back. First time we're not getting it right on the first try. So, but this is also like if you have an Oracle, you can just use it right away. And, you know, it's okay to be wrong because I mean, we're not even penalized for having getting it wrong in the first try. So it's okay. I mean, I'm pretty sure the 1357 is correct because that's always just going down, going down, going down. But then for down two, should we just, I'm wondering if we could just special case that one. So what is that going to be? Oh, wait, I think maybe it's because we are taking every other coordinate but we should really be taking every other input. And then this should be right. And then we don't actually, I think maybe that was the issue. Yeah, I think that's the issue. We were like taking every other coordinate but we should be taking every other input. So we got 178, 7178. We're taking every n down, 3, 1, non-exhaustive pattern YYS in line 18. I think, so how does it work? Let's see. Take every n, 2, 1, 2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11. Yeah, so we take line, right, because we always want to take 0's line and then line 2. So these are the lines of the inputs. So we always want to take the first one and then we take every other after that. But we get an exception. So you know, so this will be essentially same as doing this, right? 0, 2, 2, 7, 6, yeah, 0, 2, 4, 6, 6, exactly what it would want, right? But this is wrong because this will be an empty list sometimes. So let's just do it here. k's off n-1-x's off. So if it is, we're not at the end, that's okay. This is why we defined this for, we were thinking about cycling, right? And we defined it for infinite structures. But then we're applying it to the input, which doesn't actually, which isn't infinite, right? So this is why we have to deal with it. So if we're applying it to an empty list, okay, so here we want this. But if we have the empty list, so I mean, so this will just be if it's anything else. Reload, now take every end here. 0, 2, 4, 6, 8, 10. Okay, let's see in the input here. So 0, okay, start here. Let me go right one down 2. This is line 2, right one down 2. Just line 0, 1, 2. Okay, we can actually look at the test input. Okay, so we have line, this will be line 0. So it's going to be minus 1 here. So 0, right one down 2, line 2. Right one down 2, line 4. Right one down 2, line 6. Right one down 2, line 7. Line 8, right one down 2, line 10. Okay, this is a different answer, but we still get the other one correct. I think this is the right one. So we should be taking every other coordinate, right? That was, that wasn't right. We should have been taking every other line, which we are now doing, right? Let's see, see if this is the answer. All right. That was the right answer. So we are one goal, start closer to saving our vacation. And we got to do some debugging this time, instead of just getting it right, which is hopefully more fun for you guys. It's not so much fun just to see me write the code. We want to explore why we were wrong on it. And why were we wrong here? Well, we tried to take every other chord, so we were like, okay. We should take every other something, right? But, you know, we thought, okay, let's take every other coordinate, which, luckily for us, actually works for the test data. But it didn't work for the input. So I think, and I think this is correct, right? So we want to, we want to take every other line and then, yeah. All right, so people don't like the music. All right, now it's at minus 42, 44.4 decibels. But, yeah. I tried, I tried applying compression to the audio. And it's like, it's a, it's a poster. I just, I just don't talk a lot enough when I'm, that's the problem really here. I, yeah, I mean, it is duct, right? I'm literally transmitting the music because it's Christmas music. You're not hearing it through the microphone. You're hearing it from Spotify itself. Like I'm streaming what I'm hearing, right? It's an additive code stream. You're gonna, you need Christmas music, right? And this is cozy Christmas music. Anyway, I hope it's better now. I tried, so I am capturing the input and it's being duct also by the input capture, but yeah. Anyway, thanks for looking in today. I'll be back tomorrow, six o'clock sharp for episode four. And we can see that it's getting progressively harder and harder, right? So, you know, who knows? Maybe tomorrow I won't even be able to do it. I think I should set a maximum. You know, if I'm spending three hours on it and not making any progress, then that's a bit too much. But you know, it's part of the fun, right? Figuring out how to do it. And that's also like, I don't know, that's how we solve things usually. I try my best. And then if that doesn't work, usually better to just go do it. Go do something else for a short while, take a break, you know, go for a walk, then come back and do it again. So, worked for me so far. Anyway, thanks for dropping in and see you all tomorrow, six o'clock. And if you're watching this on YouTube, you missed it live, but you know, there's a link in the description where you can check out the stream. Alright, see you all.