Hi, everyone.
So in the last video, we discussed the discussion, we up to one now.
In this video, we will implement the brute force solution.
So what is the brute force of brute forces?
You have three options.
So you can do in minus one.
You can do it by two and you can do it by three.
You can only do one by two if and only if the number is divisible by two.
And similarly, you can only do it by three if the number is divisible by three.
So brute force solution is all the possible.
But try this, but try this part and try this part and take the minimum of them.
So basically we will use recursion to implement the brute force solution.
So, Indigo's, let us take an example.
So let's see if the value of Venezuela.
So what we will do, we will write also.
So first option is decrease by minus one.
So I will reach 11.
Second option is to sell by two.
So I will reach a six.
So second option is to divide by two.
And the third option is divide by these two by three.
So I will alter column for now what I will do.
So I will ask Rogozin what is the answer for 11?
So what is the answer I want to reach when?
What is the answer?
If I want to reach from 11 to one selected, the answer is I will study on a variable X.
Similarly, I will ask the question what is the answer for reaching from six to one?
I will store the answer on variable Y and similarly I will ask the question what is the answer if I
want to reach from four to one?
And I was told I was very blessed and finally able to live with my answer.
So my answer basically the minimum of one, so minimum of X, Y and Z.
And obviously I have to add plus one because I took one bad, OK, one of these three following, but
I took one bite.
So that's a plus one.
Now if the value of any seven, if the value of any seven.
So what will happen.
Seven.
Seven will call on six.
I can call minus one cancel call.
So seven is not usable by two.
So this call is not valid.
Similarly, seven is not divisible by.
So this call is not valid.
So at this point for seven, I have only one solution.
I have only one call for six.
OK, I will only call on six.
I cannot call.
Because the seven is not deisel by two or three now.
That's right, the cold.
So I have this function and steps it is taking and as input and I have to reach one.
So first let us discuss the best case.
So what is the best case?
What will be our best case?
So basically is very simple.
So if.
I'm able to reach one if I'm standing at one.
What is the minimum steps, more steps?
Zero simple or you can also do so if the number is less than close to one, you can return zero.
Simple.
Now, let's do the recursive call.
So I have three options, so the first option is let's do it in a variable X, the first option is let
us call the function M. Steps.
And minus one, so I'm stalling the inevitable.
The second option is.
What can I do?
I can divide the number by two, and similarly, the third option is.
Million steps and and Betty.
But you cannot go alone and vital if the number is not, why do so?
Basically, you can see an example here.
So for seven.
I can only call on six, I cannot call on seven by two, and similarly I cannot call seven by three
because seven is not diesel by two and the seven is not diesel by three.
So I have to write a check.
So what can I do?
So you have to write.
I have a condition.
So if the number is divisible by two, then only you can call.
Then only you can go along and buy two.
And similarly.
I will have if the number is divisible by 10, then only I can go on and buy three.
Now, after finding out X, Y and Z, what we have to do, we have to find our final output, so let's
calculate our output.
Let's calculate our answer.
So what will be that answer?
So I told you, I have to take M.F. also industry's main function.
So this main function is in built function in C++.
So I have to take a minimum of two things.
So X, Y, Z.
OK, so after take a minimum of two things.
So actually this is wrong.
So the inbuilt function in C++, so I have a function minimum, this function makes two arguments ENB
and what it will return, it will return me the minimum of the two numbers.
But here in this case, in our situation, I have Tinamba, X, Y and Z.
Still, if you will write like this minimum of X, Y or Z.
So obviously this is this will not work because the minimum function takes only two argument.
So how can I use a minimum function to find the minimum of Tinamba?
So I will write something like this min first number.
And the second number is I will call a minimum function again and I will give Y and Z.
So this is my first number.
Then minimum function will find out the meaning of these two.
So let's say the minimum is Y then this minimum function.
This is the first argument and this is the second argument.
So if you want to find out the minimum of three numbers, you can write like this.
So actually, this minimum function, I think it is implemented in Zimet Liberi.
So what I have to do, I have to find him involved in ambush, so I will use minimum function two times.
And after finding out the minimum, after calculating of said, sorry, I have to do plus one also plus
one as discussed and after calculating of it, I said we can return our answer.
Simple now is our solution, right?
So check the scope of BNZ so is very valid here.
Know the scope of why is only headline number 14 and similarly, the scope of that is only the line
number 17.
So Y and Z are not defined headline number 20.
So what I have to do, I have to write Y and Z above.
So I have to declare Y and Z here.
OK, so remove Integer from here.
Now, is that right?
So our goal is not right, why it is not right.
So let us try to understand what is the problem with this cold?
So let's say the value of an is seven.
So what will happen?
Seven will call on six.
Seven cannot call because it is not the seven is not used by two.
And similarly, we cannot call on seven by three because seven is not duCille by three.
So I will call the occasional six and let's say it reaches one and let's say the answer is no steps
is basically X.
So what does Y contain since I only declare Y and Z, so Y and Z, they both contain garbage value.
Why?
They both contain garbage value and what I am doing at this line, I'm using the minimum function.
I am trying to find out the minimum of X, Y and Z.
So Y and Z are garbage.
So what is the value of x axis, let's say so from six, I will reach.
To and from two, I will be able to reach one, so the value of X is basically to OK, so access to
Y is garbage, that is also garbage and I am taking the minimum of these three.
So obviously this is wrong.
So what can I do?
So that means I have to initialize in garbage can be anything, garbage can be anything.
So that means there is a need for initializing Y and Z.
So can I put Y equals zero and that equals zero.
So if you put viticultural that equals zero sum.
What is the value of x axis two and if you will take the minimum of X, Y and Z, so it will come out
to be zero and then you will add plus one.
So zero plus one and then you will return your answer.
So basically you will return one as your answer.
And obviously one is wrong, one should be wrong.
So your answer should be from seven.
I will go six, then two and then one.
So the correct answer is basically three and you are returning one.
So what I have to do, one thing is very clear.
I cannot initialize with zero.
I cannot naturalizer zero.
So what I will do, I will initialize y with plus infinity and I will initialize that with plus infinity.
So if I will take the minimum.
So minimum of excess to Y is plus infinity plus infinity.
So the minimum will come out to be two and I will add plus one to two plus one is three.
So I will return three as my answer entry is the right answer.
And what is plus infinity so pleasant.
It is nothing in C++ it is intermix.
And what is the meaning of Interex.
So the maximum number that can beta cancel the maximum number that can distort an integer variable.
So it is very clear that I have to initialise Y and Z, so let's initialize so Y equals Z equals Intermix.
OK, so I have initialised Y and Z, so now let us call our function now let us based our function.
Soucy out the name of the Functionalism Insteps.
And let's give the value in.
OK, so let's start program.
So let's say the value of any seven, so I would say is going to be three, the guys from seven, I
will reach six from six to and from two, one, two, three steps.
Now, let's say the value of NPS is basically 10.
So the answer is coming out of Italy, so from then I will reach nine from nine three and then one to
ten, nine, 11.
So three steps forward and two steps.
And now their distaste for 11.
So for 11, the steps is coming out before, so let's check federal solution is quite wrong.
So for 11, my gold is giving me output for wifehood because from 11 I can reach 10.
From ten, I can reach nine.
And from nine I can reach three and then one.
OK, so four steps, one, two, three and four.
So basically our goal is working fine.
It goes in.
Gold is working fine now.
Now try to implement memorisation.
OK, so try implementing memorisation solution, I will see you in the next one, Alloway.