Elixir Excerism Track - Lesson 5 "Secrets"

Elixir
Transcript

English (Auto-generated)

Hello. Today we are going to be continuing with our exorcism elixir track and we're gonna be working on the secrets exercise which is the next one in the track. Um I have gone ahead and already downloaded the local version um to my folder here. It's just so that you can see the code as I go. Um As you can see I just pasted it directly in my terminal um in the right thing and it downloaded everything I needed to it. So we're gonna go ahead and we're gonna start solving it now. So let's look at what we need. So this exercise you've been tasked with writing the software for an encryption device that works for performing transactions on data. You need a way a way to flexibly create complicated functions by combining simpler functions together for each task. Return an anonymous function that can be invoked from the calling scope. All functions should expect integer arguments, integers are also suitable for performing bit wise operations. In a lecture. A lecture. A lecture. Okay so implement Secrets Secret AD. And it should return a function which takes one argument and adds it to the argument passed into Secret AD. Mhm. Alright. So short term function which takes one argument and adds it to the argument passed into Secret AD. Perfect. So what we're gonna do is we're going to when was this one here? And we're getting the secret already. So we want to do is we want to have a function. The ads it to the argument function takes in one argument and adds it. Okay so we're going to create an anonymous function. We'll do F. N. X. And so this is the argument is going to take in and we're just going to add secret to it. She returned function which takes one argument the ex and adds it to the argument passed into secret ad. Which is this one here. Perfect. So that should run there. I forget how to run the tests in a while since I've done this um Mixed tests. Six. Yeah. Perfect. So they're all gonna have failed except for hopefully the very first one that we did. Yes a secret add both of those past. Excellent. So we can move on to the 2nd 1 implement secret secret subtract. It should return to function which takes one argument and subtracts it from the secret passed into secret subtract. So basically the exact same thing we did but instead of adding we're going to be subtracting so we can go ahead and do Mhm minus secret and Perfect. Are subtract ones past there create a multiplier should return a function which takes one argument and multiplies it by the secret past into secret. Multiply. So just like what we did above their F. N. X. X. Times secret Excellent. Create a divider should return a function which takes one argument and divides it by the secret past into secret divide so we're gonna do FN X. And the division function in elixir I believe returns a float. What's a home. Mhm. Pretty sure Cast the numbers and floats and gives a float results. So we needed to be integer. So let's get we're gonna have to actually use a div command here so we can get a proper float. So let's go ahead and do if and we will provide it the X. And then the secret. Perfect. So those ones past um set up. Okay so create an ender implement secrets Secrets End. It should return a function which takes one argument and performs a bit wise end operation on it and the secret passed into secret end. Alright so bit wise and mhm. String function which takes one argument performs a bit wise. End operation on it. It's a bit wise for calculations on bits mm. Okay so let's do I'm just gonna call bit wise directly as opposed to signing it to something else. So let's create our anonymous function here and then we're gonna do a bit wise. That's we want to do it. Mhm. Okay. Wise thoughts and didn't. Oh no we need to do. Okay so it's the end the end. Yeah and then it will take in here taking our two arguments there. Alright so let's add in the X. And the secret. Perfect. It's old news or Return function which takes one argument and performs a bit wise or operator on it and passes it into secret source. Let's look up at the store one here heartaches too. So it should be basically the exact same thing as we just did but just with a different command, let's actually just go ahead and copy this instead of rewriting it every time. That should be perfect, correct. And now we need to do the last one so create a function combine er implement secrets combined, should return a function which takes one argument and applies it to the two functions passed into secret combine in order Should try to function which takes one argument and applies it to the two functions passed into secret combined in order. Okay so in order perfect. So we can use the pipe operator then. Okay so we can do different X. Hold X. And I'm actually going to let's just drop this below for formatting here and then we can use the pipe operator so we can apply the one argument it takes and we can pass it into secret function one. And then everything you're calling an anonymous function, you need to use that dot which does explain as you can see that dot there. Um If we go here um use a dot before this was calling an anonymous function. Mm Perfect. So we'll do that. And then what is the exact same one for the second one? Clinch awesome. All of our past our past there. This one is a little confusing. Um for sure because it's making functions and assigning them to there's a function within a function. So I definitely recommend you look up anonymous functions if you aren't understanding that as well. Um But I hope this helped, and we will see you in the next exercise.
163 Views 1 Likes 0 Comments

Let's tackle the Secrets exercise on the Exercism Elixir track!

Comment
Leave a comment (supports markdown format)