 As I make this video I respectfully acknowledge that I am standing on the unceded traditional territory of the Comox First Nation and I thank them for the use of their lands. This is the third video in a series where I was given a string and the goal was to return the first n words of the string, in this case of course the number of words is 4 and I've done that with n0 in the very first video of the series and when I got some metrics about it using time space X and the way time space X works is that it takes the left argument and that's the number of times it executes the right argument which is a string and then what it returns is the amount of time and the amount of space hence time space X so that's the amount of time and space that the first version took me and then I did an alternate version which I called n1 and you can see it's quicker and it takes up less space and it's important that it takes up less space because as you get bigger and bigger arguments for s that space increases quite a bit more and it runs quite a bit slower as it gets bigger so the with these small arguments the quicker you can make it the less space it takes the quicker it'll be and today we're going to take a look at what I did to come up with n2 and just to show you n2 is hmm it looks like it's slower that's interesting I'm going to run that one more time because sometimes you just get hitches in the computer there you go that's more like it n2 runs faster and it always takes up less space there's the space part of it is quite consistent but sometimes you've got something running in the background on a computer and it takes up a little bit more space but n2 is faster takes up less space so how did I write n2 well starting off with s which is our string I wanted to find out all the positions in this string that were blank and what I want to do is any of those positions that are blank I'll say equals so between the quotes here that's a blank equals s and there I go now got now I've got a string of ones and zeros and the ones are all in position where there's planks that's great except this really isn't a verb it's sort of more just a statement so I'm going to make it into a verb and the way I'm going to make it into a verb is I'm going to make it into a verb called a fork so whoops it's a little separation there so this verb here and this whole thing here is a verb this right indicator is going to pull the s in and on this left time of the fork I've got a blank space and so the blank space feeds one side of the equals verb and the other side of the equals verb is going to be my string and what that means is it's going to compare the blank space to every character in this list in this string and whenever it sees a blank it's going to return a one and whenever it sees anything else it's going to return a zero so there you go same as before but now this is actually a verb so it's separate from your noun so now that I know where now I know all these positions of ones it would be great if I had a verb that would actually give me the numbers of those positions because if I can find the number of the positions say here then I could just take all the characters up to that position well we actually do have a verb that does that called indices and that's what indices look like now if you remember from previous videos the way I've got this now is this group of three would be a fork and then this extra verb here would make it a hook I don't want a hook I don't want s coming back in and feeding in the other side of this one I want nothing coming in from this side I want this whole verb here just to feed into this like there was nothing there and that's why I'm going to put a thing called a cap here which is basically a dead verb it takes a space of a verb but it doesn't feed anything here so everything is coming from this side and that means this string of ones and zeros goes in to indices treats it like a monadic verb and when I get back is a list of the indices of the ones remember it's zero index so this is zero and then I've got a one in one position two three four five six like that and then so on down the list so these are all the positions I've got and now I've pretty much got what I want there but I'm gonna have to pull in somehow I'm gonna have to figure out when I want to get to this index here which is say if I had four this will be where four comes in zero one two three four but I don't want this extra one I want to be back here so I'm gonna have to decrement my right argument out of this group so what I'm gonna do is I'm going to create a verb here that's going to be a cap and then a decrement and then the left argument and in the middle I'm gonna do from so essentially when I put the four out here what's gonna happen is this left argument means the four comes in here and it gets processed decremented so it becomes three take and then this verb here this fork here is taking the right argument so it's going to return this list it's gonna take the third because I've got three here it's gonna take the third position here so zero one two three that will give me 15 bingo so now I know 15 spaces in is all the characters that I want so having done that I'm gonna create one more fork but I'm gonna do it in a slightly different way I'm going to take this whole thing and it's gonna become my left time of my fork and then in the center I'm going to put take and then only on the right time I'm gonna put self again so now I'm taking 15 characters of s and I get a list of words so there's my answer and when I do in two that's what it looks like I've got taking s taking what up from s while I'm taking some number of characters out of s what number of characters will I have to evaluate this whole thing here and it takes s what's equal to spaces the indices of them and then on this side it takes four decrements so it's got three taking the third index which is 15 and you get a list of words now I also created another noun called s one that had 380,000 characters in it and because the original s has 38 characters essentially there's 10,000 copies of s one there now the reason I did this is just to show you what happens if I use bigger arguments and you'll be able to see that you get a much bigger difference between them so the spinning beach ball of I'm taking my time and it took about almost four thousandths of a second to do that a thousand times which is quick it also took up a lot of space let's take a look at and one now it's a bit quicker and takes up less space because we got to the 10 to the minus 6 and said 10 to the minus 7 so essentially this is about two and a half times bigger I'm just ballparking there but now this is where you really start to see the difference within two because it's oh what would it be about one seventh the time of this one but look it's even taking a third of the space so if you were constrained by your space on what you're trying to do this particular verb is much quicker and takes up less space than the other two so that's my quickest verb and I'm going to have one more video in the series and in that video I'm going to look at what I think is a really elegant way to do this but it's not the fastest it's just in some ways it's the prettiest so the last video in the series will be about something I think is kind of pretty but honestly it's it's probably not the most efficient way to do it the most efficient way to do it as this guy right here it's the big difference is using the indices it means I'm not trying to create all these cumulative lists and everything I'm just taking a list of numbers I'm only decrementing a single number and I'm just taking whatever that number is from the whole string it's a very quick thing to do if somebody else comes up with a quicker thing I'll include it in the comments because I'd love to learn about it but at this point this is the fastest way and the least space that I've found so if you find out find a better one well put in the comments and I'll I may make end up making two more videos then because I'd love to find out that there's there's there's a faster way but I haven't found it yet and I think that's about it for this one