Hi, everyone.
So in this video, we are going to solve this question of.
So it's a very popular game and the game is very simple.
So these are endless.
And you have people, so this is the source, destination and helper, so we're here to do so.
You need to move this and desk from here.
From source to destination.
So if this is for three, two and one, if this is the name of the risk, then that Air Force should
be presented then three.
Then two and then one, so you need to move all the desk from source to destination, so so this will
become empty and the station will contain all the risk.
And the rules are you can move one desk at a time, you can pick one desk and you can move one desk
at a time.
So you are given a helper.
So what you can do, you can take the help of basically poll simple and basically you can put a small
desk above big desk.
So this is right.
This is wrong.
You cannot put a big desk.
Above small desk.
OK, so these are the rules and we have to find how many steps we will take to transfer any disk from
source to destination.
So let's take a small example.
So if the value of anyone so if there's only one, what do you to do this is useless helper and destination,
so let's name it ABC.
So I have only one disc.
What can I do, I can actually put it here.
We need to move on this time so I can actually put it here.
So how many steps?
Only one step forward and equals one.
My answer will be one simple if the value of any is to Nazih, how many steps I will take.
So there are two risk.
So this is a.
NSB.
And this is so you have to ask this is this, too, and this is Visqueen.
So what I will do so first of all, let's remove it from here and let's put it here.
So now this was our first step.
Now, in the second step, what I will do so I can put this desk here, so in the second step, I will
put two here.
So this was our second step.
And in the third step, I can put one above this.
So I move to from here and I will put one above this desk.
And this is step three.
So now their destination is correct.
So basically, for any clues to I took three steps.
I took three steps.
So this was the first step, the second step and the third step.
So basically there is a formula and the formula is through to the power end minus one.
So if the value of any is one, if there is only one desk, so this will be one.
OK, this one will be one.
And you are getting one if the value of an E also to the power to minus one.
So this will be three and you are getting three steps.
So if the value of three, if there are three disc one, two and three, if there are three desc then
to about three minus one, you will talk seven steps.
So one way of solving this question is basically you can actually print because you know the mathematical
formula so you can actually print like this.
OK, so this will be around so you can use the mathematical formula.
But let's suppose we do not know the formula.
We do not know the formula then how against all this caution, so spoiling the situation is still very
easy.
We can use recursion using think we can easily solve this question.
So this is your source, that's namely this is your helper, let's name it be, and this is our destination
and it's name Mitzy.
So let's say there are and this president here.
So let's say they are undecided, which I want to transfer from source to destination.
So a number of ways, sorry, the number of steps I will take will be so basically let's transfer this
into minus one steps.
Let's start with this and minus one disc from source to helper.
OK, so first of all, I will transfer and minus one disc from E 2B and then I will transfer this disc
from source to destination from here to see so here and minus on this card present so and minus one
discard present here.
So this is the first step.
First step is taking my disk and put it here.
The second step is basically take the last disk and put it here.
And the third step is basically take this and minus one disk and put it here.
So you are putting this and that disk, you are putting this and this here, and then you will put and
minus one disk here.
So a number of steps will be the number of steps.
I took the put and minus one disc from A to B. So this is from me to be.
Plus one, because of this, I want to put this disc, the Lastra disc here.
So this is one OK, one step plus the number of steps to put this and minus one disc from B to C.
So and minus one, and this is the number of steps to put their desk from B to C, so sees their destination.
It was the source is the source and be the helper.
So now we have a reconciliation, so now we have a reconciliation, so a number of ways.
First of all, I will I will put all that minus one disc from it to be.
Then.
These are they will be removed, so you have only one desk, since you have only one desk, you can
safely put it here.
So plus one, so then you need to put this in minus one desk from B to C.
Simple, so now the reconciliation is ready, so let us write the code and the biscuits will be the
number of lisker zero.
So the number of steps will be zero.
Number of steps will be zero.
So let's write the code.
So that it will be easier.
There will be in the name of the function is tomorrow, finally, it will take how MiniDisc.
This case will be the number of days gazettal.
If the number if the number of deaths gazettal.
I will take zero steps, otherwise how many steps I will take so out of energy and minus one.
Plus one plus and minus two.
And this is the final call.
And let's test our function.
So let's take the value of an input from the user an and and let's call the function.
And given.
So let's see what I'm doing here.
So I told you, this is a source helper destination.
So the approach was very clear, I have and present here, so I have ended, OK, so first step is basically
put and minus one desk from me to be so first step is put and minus one desk from me to be so number
of ways to put minus one indiscriminately.
Then you will put the last of this.
So remove it.
These are not pleasant here, so these are all present here now, so put the last disc.
And put it here, so plus one, so and minus one, plus one now plus.
So first step then.
Second step down.
So this was the first step from year to B plus and minus one from A to B.
So this is of the last me from Matosi and this will be N minus one.
And then these are N minus one this presented, so after transferring the last disc, the biggest the
largest disc so and is present here, then you need to put all this disc here.
So a number of ways to put and minus one disc from B to C, so this is from B to C.
Simple, so let's start function.
So this will be my next one.
And we know.
So let's say the value of an is one.
So the answer is coming out to be one, because the Power-One minus one, so this is one, even the
formula to the parent, minus one, we will test our function with the help of this formula.
So let's call our function for the value and equals to.
If the value of N is to.
Then the answer is three, so he used a formula to the power to minus one necessity and to use the right
answer.
So let's test.
For a bigger value, so let's say I want to test for five.
So the answer is coming out to and you will take 31 steps because truly the power five is 32, minus
one is basically 31.
So basically, if you have five risk.
Disc five for.
Three, two and one, so if you have five discon, it will take you to one step.
If you want to move all the risk from source.
To destination with the help of Helper.
OK, so you cannot solve this problem manually.
OK, so today is the right answer.
So this function was very easy.
This problem was very easy.
So this is it from this video.
I will see you in the next one.
Thank you.