1 00:00:01,850 --> 00:00:02,660 Hi, everyone. 2 00:00:02,690 --> 00:00:05,820 So in this video, we are going to solve this question of. 3 00:00:06,440 --> 00:00:10,100 So it's a very popular game and the game is very simple. 4 00:00:10,130 --> 00:00:11,660 So these are endless. 5 00:00:14,800 --> 00:00:20,440 And you have people, so this is the source, destination and helper, so we're here to do so. 6 00:00:20,440 --> 00:00:23,020 You need to move this and desk from here. 7 00:00:24,750 --> 00:00:26,310 From source to destination. 8 00:00:27,480 --> 00:00:32,700 So if this is for three, two and one, if this is the name of the risk, then that Air Force should 9 00:00:32,700 --> 00:00:34,050 be presented then three. 10 00:00:35,260 --> 00:00:42,730 Then two and then one, so you need to move all the desk from source to destination, so so this will 11 00:00:42,730 --> 00:00:45,310 become empty and the station will contain all the risk. 12 00:00:45,850 --> 00:00:51,850 And the rules are you can move one desk at a time, you can pick one desk and you can move one desk 13 00:00:51,850 --> 00:00:52,330 at a time. 14 00:00:52,570 --> 00:00:54,060 So you are given a helper. 15 00:00:54,520 --> 00:01:02,140 So what you can do, you can take the help of basically poll simple and basically you can put a small 16 00:01:02,140 --> 00:01:03,930 desk above big desk. 17 00:01:03,940 --> 00:01:04,870 So this is right. 18 00:01:05,140 --> 00:01:05,830 This is wrong. 19 00:01:06,100 --> 00:01:08,080 You cannot put a big desk. 20 00:01:09,080 --> 00:01:10,740 Above small desk. 21 00:01:10,760 --> 00:01:17,750 OK, so these are the rules and we have to find how many steps we will take to transfer any disk from 22 00:01:17,750 --> 00:01:19,060 source to destination. 23 00:01:19,430 --> 00:01:20,870 So let's take a small example. 24 00:01:22,550 --> 00:01:30,760 So if the value of anyone so if there's only one, what do you to do this is useless helper and destination, 25 00:01:31,130 --> 00:01:32,840 so let's name it ABC. 26 00:01:33,900 --> 00:01:35,460 So I have only one disc. 27 00:01:37,230 --> 00:01:39,290 What can I do, I can actually put it here. 28 00:01:40,220 --> 00:01:42,920 We need to move on this time so I can actually put it here. 29 00:01:42,950 --> 00:01:43,930 So how many steps? 30 00:01:43,940 --> 00:01:46,290 Only one step forward and equals one. 31 00:01:46,310 --> 00:01:52,650 My answer will be one simple if the value of any is to Nazih, how many steps I will take. 32 00:01:53,420 --> 00:01:54,620 So there are two risk. 33 00:01:57,190 --> 00:01:58,150 So this is a. 34 00:02:00,410 --> 00:02:01,190 NSB. 35 00:02:02,850 --> 00:02:09,000 And this is so you have to ask this is this, too, and this is Visqueen. 36 00:02:10,870 --> 00:02:15,580 So what I will do so first of all, let's remove it from here and let's put it here. 37 00:02:17,520 --> 00:02:19,530 So now this was our first step. 38 00:02:20,730 --> 00:02:26,940 Now, in the second step, what I will do so I can put this desk here, so in the second step, I will 39 00:02:26,940 --> 00:02:27,730 put two here. 40 00:02:28,680 --> 00:02:30,300 So this was our second step. 41 00:02:30,930 --> 00:02:33,780 And in the third step, I can put one above this. 42 00:02:34,050 --> 00:02:38,670 So I move to from here and I will put one above this desk. 43 00:02:38,970 --> 00:02:40,940 And this is step three. 44 00:02:41,310 --> 00:02:43,720 So now their destination is correct. 45 00:02:43,950 --> 00:02:46,920 So basically, for any clues to I took three steps. 46 00:02:47,730 --> 00:02:48,870 I took three steps. 47 00:02:49,350 --> 00:02:54,000 So this was the first step, the second step and the third step. 48 00:02:54,510 --> 00:02:58,210 So basically there is a formula and the formula is through to the power end minus one. 49 00:02:58,920 --> 00:03:03,990 So if the value of any is one, if there is only one desk, so this will be one. 50 00:03:04,030 --> 00:03:05,610 OK, this one will be one. 51 00:03:05,610 --> 00:03:10,920 And you are getting one if the value of an E also to the power to minus one. 52 00:03:11,400 --> 00:03:13,590 So this will be three and you are getting three steps. 53 00:03:13,860 --> 00:03:20,160 So if the value of three, if there are three disc one, two and three, if there are three desc then 54 00:03:20,280 --> 00:03:23,670 to about three minus one, you will talk seven steps. 55 00:03:25,020 --> 00:03:29,520 So one way of solving this question is basically you can actually print because you know the mathematical 56 00:03:29,520 --> 00:03:31,890 formula so you can actually print like this. 57 00:03:31,920 --> 00:03:35,060 OK, so this will be around so you can use the mathematical formula. 58 00:03:35,310 --> 00:03:37,710 But let's suppose we do not know the formula. 59 00:03:39,310 --> 00:03:44,590 We do not know the formula then how against all this caution, so spoiling the situation is still very 60 00:03:44,590 --> 00:03:44,810 easy. 61 00:03:44,840 --> 00:03:49,240 We can use recursion using think we can easily solve this question. 62 00:03:50,700 --> 00:03:57,460 So this is your source, that's namely this is your helper, let's name it be, and this is our destination 63 00:03:57,460 --> 00:03:58,380 and it's name Mitzy. 64 00:03:59,920 --> 00:04:03,040 So let's say there are and this president here. 65 00:04:05,150 --> 00:04:10,970 So let's say they are undecided, which I want to transfer from source to destination. 66 00:04:12,480 --> 00:04:19,769 So a number of ways, sorry, the number of steps I will take will be so basically let's transfer this 67 00:04:19,950 --> 00:04:21,260 into minus one steps. 68 00:04:21,540 --> 00:04:25,630 Let's start with this and minus one disc from source to helper. 69 00:04:26,560 --> 00:04:35,200 OK, so first of all, I will transfer and minus one disc from E 2B and then I will transfer this disc 70 00:04:36,040 --> 00:04:42,760 from source to destination from here to see so here and minus on this card present so and minus one 71 00:04:42,760 --> 00:04:43,690 discard present here. 72 00:04:43,960 --> 00:04:45,250 So this is the first step. 73 00:04:45,550 --> 00:04:48,190 First step is taking my disk and put it here. 74 00:04:48,820 --> 00:04:52,710 The second step is basically take the last disk and put it here. 75 00:04:53,530 --> 00:04:57,360 And the third step is basically take this and minus one disk and put it here. 76 00:04:57,820 --> 00:05:04,150 So you are putting this and that disk, you are putting this and this here, and then you will put and 77 00:05:04,150 --> 00:05:05,180 minus one disk here. 78 00:05:06,010 --> 00:05:09,580 So a number of steps will be the number of steps. 79 00:05:10,700 --> 00:05:15,710 I took the put and minus one disc from A to B. So this is from me to be. 80 00:05:17,200 --> 00:05:22,750 Plus one, because of this, I want to put this disc, the Lastra disc here. 81 00:05:23,990 --> 00:05:32,270 So this is one OK, one step plus the number of steps to put this and minus one disc from B to C. 82 00:05:33,680 --> 00:05:40,160 So and minus one, and this is the number of steps to put their desk from B to C, so sees their destination. 83 00:05:41,090 --> 00:05:43,970 It was the source is the source and be the helper. 84 00:05:45,820 --> 00:05:53,250 So now we have a reconciliation, so now we have a reconciliation, so a number of ways. 85 00:05:53,260 --> 00:05:56,770 First of all, I will I will put all that minus one disc from it to be. 86 00:05:57,800 --> 00:05:58,190 Then. 87 00:05:59,180 --> 00:06:04,340 These are they will be removed, so you have only one desk, since you have only one desk, you can 88 00:06:04,340 --> 00:06:05,360 safely put it here. 89 00:06:07,300 --> 00:06:12,790 So plus one, so then you need to put this in minus one desk from B to C. 90 00:06:14,950 --> 00:06:20,260 Simple, so now the reconciliation is ready, so let us write the code and the biscuits will be the 91 00:06:20,260 --> 00:06:21,420 number of lisker zero. 92 00:06:21,820 --> 00:06:23,710 So the number of steps will be zero. 93 00:06:23,750 --> 00:06:25,240 Number of steps will be zero. 94 00:06:26,380 --> 00:06:27,460 So let's write the code. 95 00:06:28,620 --> 00:06:30,240 So that it will be easier. 96 00:06:32,130 --> 00:06:37,950 There will be in the name of the function is tomorrow, finally, it will take how MiniDisc. 97 00:06:39,010 --> 00:06:41,200 This case will be the number of days gazettal. 98 00:06:43,080 --> 00:06:45,300 If the number if the number of deaths gazettal. 99 00:06:46,330 --> 00:06:54,700 I will take zero steps, otherwise how many steps I will take so out of energy and minus one. 100 00:06:55,790 --> 00:06:59,960 Plus one plus and minus two. 101 00:07:00,880 --> 00:07:02,380 And this is the final call. 102 00:07:03,280 --> 00:07:04,660 And let's test our function. 103 00:07:08,190 --> 00:07:13,800 So let's take the value of an input from the user an and and let's call the function. 104 00:07:15,930 --> 00:07:16,680 And given. 105 00:07:19,740 --> 00:07:21,140 So let's see what I'm doing here. 106 00:07:24,410 --> 00:07:29,930 So I told you, this is a source helper destination. 107 00:07:31,150 --> 00:07:38,740 So the approach was very clear, I have and present here, so I have ended, OK, so first step is basically 108 00:07:38,740 --> 00:07:47,830 put and minus one desk from me to be so first step is put and minus one desk from me to be so number 109 00:07:47,830 --> 00:07:50,240 of ways to put minus one indiscriminately. 110 00:07:50,620 --> 00:07:52,570 Then you will put the last of this. 111 00:07:52,630 --> 00:07:53,260 So remove it. 112 00:07:54,690 --> 00:07:59,730 These are not pleasant here, so these are all present here now, so put the last disc. 113 00:08:00,850 --> 00:08:06,680 And put it here, so plus one, so and minus one, plus one now plus. 114 00:08:07,480 --> 00:08:08,400 So first step then. 115 00:08:08,410 --> 00:08:09,250 Second step down. 116 00:08:09,270 --> 00:08:12,910 So this was the first step from year to B plus and minus one from A to B. 117 00:08:13,300 --> 00:08:18,280 So this is of the last me from Matosi and this will be N minus one. 118 00:08:19,330 --> 00:08:25,450 And then these are N minus one this presented, so after transferring the last disc, the biggest the 119 00:08:25,450 --> 00:08:29,770 largest disc so and is present here, then you need to put all this disc here. 120 00:08:30,130 --> 00:08:35,679 So a number of ways to put and minus one disc from B to C, so this is from B to C. 121 00:08:36,700 --> 00:08:39,250 Simple, so let's start function. 122 00:08:40,120 --> 00:08:41,500 So this will be my next one. 123 00:08:43,669 --> 00:08:44,570 And we know. 124 00:08:47,970 --> 00:08:50,430 So let's say the value of an is one. 125 00:08:51,900 --> 00:08:58,520 So the answer is coming out to be one, because the Power-One minus one, so this is one, even the 126 00:08:58,560 --> 00:09:03,540 formula to the parent, minus one, we will test our function with the help of this formula. 127 00:09:04,500 --> 00:09:08,190 So let's call our function for the value and equals to. 128 00:09:10,550 --> 00:09:11,900 If the value of N is to. 129 00:09:14,130 --> 00:09:20,130 Then the answer is three, so he used a formula to the power to minus one necessity and to use the right 130 00:09:20,130 --> 00:09:20,500 answer. 131 00:09:20,850 --> 00:09:21,720 So let's test. 132 00:09:24,010 --> 00:09:27,280 For a bigger value, so let's say I want to test for five. 133 00:09:28,260 --> 00:09:34,950 So the answer is coming out to and you will take 31 steps because truly the power five is 32, minus 134 00:09:34,950 --> 00:09:36,550 one is basically 31. 135 00:09:36,840 --> 00:09:38,640 So basically, if you have five risk. 136 00:09:39,760 --> 00:09:42,040 Disc five for. 137 00:09:43,560 --> 00:09:48,570 Three, two and one, so if you have five discon, it will take you to one step. 138 00:09:49,600 --> 00:09:52,060 If you want to move all the risk from source. 139 00:09:53,480 --> 00:09:55,570 To destination with the help of Helper. 140 00:09:55,880 --> 00:09:58,480 OK, so you cannot solve this problem manually. 141 00:09:58,970 --> 00:10:01,070 OK, so today is the right answer. 142 00:10:02,180 --> 00:10:03,660 So this function was very easy. 143 00:10:03,830 --> 00:10:05,180 This problem was very easy. 144 00:10:07,610 --> 00:10:09,050 So this is it from this video. 145 00:10:10,000 --> 00:10:11,320 I will see you in the next one. 146 00:10:11,650 --> 00:10:12,130 Thank you.