 As I record this video, I respectfully acknowledge that I'm standing on the unceded traditional territory of the Comox First Nation. I thank them for the use of their lands. This is a second video in a series and the challenge that I've got is if I've given a string, which in this case is a list of words to use as a target, I want to define a verb that will allow me to select N words from that string. So the verb in this case is N zero, N zero, zero, and it looks like that. And if I provide it with a left argument of four and a right argument of S, it's going to select a list of words because those are the first four words. The way it does it, I really quickly touch on it. If you want more details, look at the first video because I kind of go through it at that point. This together, these two verbs in the parentheses are form a hook. And what a hook does is its leftmost verb takes the left argument on this side and then the results of this verb on this side and this verb on this side only works on the right argument. So the right argument works through here and the results of that becomes the right argument to this verb and the left argument to this verb is that first four. So it comes in on one side and then the result of this working on the right argument. Within each of these, these are both forks. And the way forks work, hooks, which I just described, are two verbs. Forks are three verbs. And the forks work so that the outside verbs, this time and this time, both work on their argument. So in this case, because S is only working in this verb, the S has a space appended to it. And then this is called a cap and it does nothing. And so normally if it did anything, it would be working on S, but it does nothing. So what happens is now this adds a space to the end of S and then it just feeds its result to here, which is cut. And it boxes each part of the string whenever there's a space. So they're boxes around each word essentially. Take that result. So now I've got boxes around each word and now I have a four on this side and I've got this result on this side. So I've got four coming in here and all these boxed words on this side. This first verb, this is again a fork because it's got three verbs. This verb is doing nothing. This verb now has two arguments. It has the result from here, which is all the boxes. It has the four on this side and this is take. So it's going to take the first four boxes and it's going to feed that result to here, which is raise, which gets rid of the boxes and you end up with a list of words. That's how it's doing it. Now, in the previous comment section, somebody suggested they may have found, I said that I knew other ways to do this and I was going to explore those, which is what I'm going to do right now. But they think they found the same way that I have found and I think they're right. It's not the fastest way, but the reason I think they're right is because they gave me the results of their time space X and their space used was exactly the same as what I'm going to show you right now. So it'll be really interesting to see whether my version is quicker than theirs because it's possible mine slower, but it's using the same space or whether they've actually found something that's quicker as well. One thing I know is it's using the same space. So how do I come up looking at this a different way? Well, let's look at us again. Always helps to look what you're given to start with. I now am going to take a slightly different approach to this. What I want to do is I want, whenever I see a space, I want to put in a one and whenever I see not a space, I want a zero. And this is really easy to do in J because there's a space equals and S. So whenever the space equals the character in S, I'm going to get a one. And when it doesn't, I'm going to get a zero. So that's pretty straightforward. Tell you what, let's make this a verb, like a verb that I can use like a fork so that I'm not so dependent on having S in that spot. So what I'm going to do there is essentially again, this is a fork. It's a verb, a verb. Oh, but this is a noun. Well, I'm allowed to do that with forks as well. In this position on the left side, I can use a noun. So a verb, a verb and a noun just acts like this was a verb that just returns this now. So it's saying a blank equals this and this shape, this square bracket says, look at this argument. So right away, I've got the same thing. Next step I'm going to do is I'm going to throw this in and I'm also going to throw in a cap. Because I've got one, two, three here. So that's essentially a fork and it's feeding to here. And since this is a fork, I don't need to mean to just feed straight across same as the forks were using in the past when I put a cap in. But what does this do? Well, let's hit return. That's what it does. Well, how does it do that? Well, it's kind of neat, actually. These two, this backslash and forward slash are both called adverbs. This plus is a noun. It's addition. So let's take the adverbs in order. So this adverb here is called prefix. And what prefix does is whatever this verb here is, and together an adverb and a verb do form a verb. Whatever that verb is, this is going to take the prefixes of that whole list. So this adverb is going to chop this into first, just taking this first zero and then it's going to take the zero and one. And it's going to take the zero, one and zero and it's going to work its way until it's got the whole list and it's processing the whole list. And what's it processing it with? It's processing it with this. And what the plus insert does is it puts plus between each of the items of the list. So the prefix is first just a zero and plus zero is zero. And then prefix does zero and one. And I put a plus between the two and I get one now. So in this position I get one. I do prefix one more time and I get a zero. Now adding a zero to one, zero, one, zero, I'm still going to stay at one. I'm going to stay at one all the way along this list until I hit another one. And essentially what this is doing is giving me a running total of every one that I hit increases this number here. So I'm building up a running total of the sums of all the ones in the list. Great. Well, what does that do for me? Well, what it does is if I wanted to take the first four words, there's the first word is a zero. These ones are the second word. These twos are the third word. These threes are the fourth word. So if I, for instance, did this and I just made it a hook, right? Because I've got this verb. This whole part here was a fork and now I've added one more verb. So this is going to be one verb and then this is going to be one verb. This is greater than, but now because it's a hook, the state return here, I'll put the four in here. And now what it's doing is this whole thing here and what I'll do is I'll put parentheses around it just to make it a little more obvious. You don't need them because of the way J processes things. But in this case, I'm just making it this whole thing here is a verb and it's only working on S. And then the results of that four is greater than what the results are. Well, we know what the results are here. We're going to get a zero whenever four is not greater than and we're going to get a one whenever four is greater than. So essentially we just created a mask here. All the ones correspond to the first because we're zero indexed one, two, three, four words and then it'll get rid of the rest of them. So how do we do that? It's actually really simple. There's a word called copy and what copy does is four fives gives me four fives. It copies whatever the left argument is. It makes four copies of the right argument. This gets really interesting when you've got say zeros and ones and I'll give it five, six, seven. Look what happens. When I've got one, I get one copy of five. When I've got zero, I get zero copies of six. It never shows up. I get one. I get one copy of seven. Well, look at this mask now whenever I've got a one, if I use copy on S, I'm just going to copy the things across that I need. So I'm going to create one more fork except in this case a fork by previous verb becomes this side of the fork and it's a hook on this side of the fork. It's just working off of S. So I'm going to take S. I'm going to use this mask and I'm going to make copies of S and it's going to return a list of words. Just the way I wanted it. So let's name that N1. And we'll do assignment that way. I'm just going to copy this. I'll drop it in there. And now I've just created N1. So let's take a look at type SpaceX, which is our way of measuring these things. And I'll give 1000 of them on the left argument because I'm going to do this 1000 times. I will do four and zero S. And the result will be the average time followed by the number of bytes that I use. So 6.93 into the seven. So what 0.6 millionths of a second and 2752 space, almost almost three kilobytes. Let's compare that to N1. It's a little quicker and it's using a whole lot less space. So I'll tell you right now I still I still know a faster way to do this. I still know a way that uses less space. And that'll be the subject of my next video. But the reason I think the person who posted their answer and they didn't actually post their answer, they posted their results. So let's take a quick look at that. I think it's here. There we go. It's ashy as me and good for you ashy as me. But you'll see the timing, the 2752 and the 1664 are the same. So they got the same result for space as I did. And they've got the same result for space here for N1 as well. What's different is I don't know what computer they're working on. So that's why I think they're using the same technique. But if they figured out a faster way to do it, their time when they actually run on their computer, my way of doing it actually might be slower. So they may have found a quicker time in which case I hope they post something to this video. But in the meantime, this is another way to select the first N words from a list of words and uses a different technique. It's making copies based on whenever the number of words is greater than the cumulative running total of the spaces. And when you think about it, it's another way of thinking about the problem, right? Whenever you've got a space, you've got a word. So if you want four words, just make sure that you're taking every space until you get to the fifth word. And then ignore the rest. And that's what the copy does. So that's what this is actually doing. It's making a copy based on whenever you're less than four words, when you're greater than four words, ignore it. And that's what copy does with the ones and the zeros. So hopefully that's useful to you. And preview of coming attractions in a couple of days, I will post another video. And in that video, I'll go and show you what I think is my quickest time so far. And we'll see whether Ashie or anybody like that is able to come up with a quicker time than this. But good for you to come up with one of the options I've come up with. I'm quite impressed actually. And it's possible that your way is even faster than mine because I've got a different computer than yours. You know, you run on your computer and see what your results look like and see whether my way of doing it is faster than yours or maybe your way is faster than mine and I will learn something. That's what it's all about, isn't it?