1
00:00:01,130 --> 00:00:01,760
Hello everyone.

2
00:00:01,760 --> 00:00:03,020
Welcome to this recession.

3
00:00:03,020 --> 00:00:08,350
So in today's session what we will do we will try to solve one more problem with the help of the occasion.

4
00:00:08,360 --> 00:00:10,720
So the name of the problem is sum of digits.

5
00:00:10,730 --> 00:00:15,230
Okay then maybe the problem is some of the digits.

6
00:00:15,230 --> 00:00:16,160
So what is the problem.

7
00:00:16,160 --> 00:00:21,050
So the problem is very simple given the value often let's say it is one two three four and five.

8
00:00:21,080 --> 00:00:25,490
What we have to do we have to add all these numbers so the addition will be 15.

9
00:00:25,520 --> 00:00:26,870
So this is our answer.

10
00:00:26,900 --> 00:00:27,430
Okay.

11
00:00:27,470 --> 00:00:30,790
So we have to add all the digits of the number.

12
00:00:30,980 --> 00:00:31,240
Okay.

13
00:00:31,270 --> 00:00:35,180
Similarly the number and is 13 and I said will be three plus 1 food.

14
00:00:35,570 --> 00:00:40,190
If the value of an is doing now there will be two plus one which is three.

15
00:00:40,220 --> 00:00:40,480
Okay.

16
00:00:40,490 --> 00:00:43,160
So I hope you got done said of the value of this five.

17
00:00:43,180 --> 00:00:44,360
And the answer will be five.

18
00:00:44,660 --> 00:00:47,630
If the value of and is zeros then the answer will be zero.

19
00:00:47,840 --> 00:00:48,340
Okay.

20
00:00:48,410 --> 00:00:52,980
So what we have to do we have to add all the digits of the number.

21
00:00:53,290 --> 00:00:53,890
Okay.

22
00:00:53,960 --> 00:00:56,240
And then we have to return the sum.

23
00:00:56,240 --> 00:00:56,730
Okay.

24
00:00:56,780 --> 00:01:00,710
So we have already solved this problem might actively using Before we divide loop.

25
00:01:00,710 --> 00:01:06,230
But now in today's session since we are learning regression we will try to solve this same problem with

26
00:01:06,230 --> 00:01:07,250
the help of the occasion.

27
00:01:07,280 --> 00:01:13,370
Okay so what triggers Genesis occasions is I will if I really can get down some with a similar problem

28
00:01:13,400 --> 00:01:15,260
and you do the calculation.

29
00:01:15,260 --> 00:01:17,190
So what it goes it will do.

30
00:01:17,810 --> 00:01:24,440
So we have to find some of digits of any number some digit of the anything number.

31
00:01:24,800 --> 00:01:25,280
Okay.

32
00:01:25,340 --> 00:01:28,920
So what recursion were ludicrous you will see.

33
00:01:29,060 --> 00:01:32,440
So what they will do I will break the problem into smaller part.

34
00:01:32,840 --> 00:01:38,350
Okay I will qualification on this part and occasion will give me the answer.

35
00:01:38,950 --> 00:01:39,940
So what do the answer.

36
00:01:40,000 --> 00:01:43,520
Because it will give me that dance have all the smaller problems then.

37
00:01:43,810 --> 00:01:47,060
So you know the smaller answer how you will conclude the bigger answer.

38
00:01:47,080 --> 00:01:49,050
What I will do smaller answer.

39
00:01:49,120 --> 00:01:50,930
Plus the last digit.

40
00:01:51,020 --> 00:01:53,090
Okay so this is last digit.

41
00:01:53,260 --> 00:01:56,500
So smaller surplus last digit will be our answer.

42
00:01:56,500 --> 00:02:00,280
So 10 plus 5 which will be 15.

43
00:02:00,310 --> 00:02:00,680
Okay.

44
00:02:01,030 --> 00:02:04,740
Similarly now how it will work internally.

45
00:02:04,780 --> 00:02:05,290
So.

46
00:02:05,710 --> 00:02:09,100
So this is our number okay.

47
00:02:09,230 --> 00:02:10,790
Let's make the whole code red.

48
00:02:10,800 --> 00:02:12,270
So what will happen.

49
00:02:12,350 --> 00:02:20,290
I will break the number the smaller part I will call the equation on this part then this is our number

50
00:02:20,430 --> 00:02:30,290
1 2 3 4 I will call that equation on a smaller product again I will call the equation on the smaller

51
00:02:30,290 --> 00:02:39,910
part again I will call the equation on smaller part and again I will call the equation on the smaller

52
00:02:39,910 --> 00:02:40,270
part.

53
00:02:41,020 --> 00:02:46,120
So this is 0 so I am calling records on this my love part.

54
00:02:46,250 --> 00:02:50,300
Okay so I am calling guys on a similar path so it will be zero.

55
00:02:50,300 --> 00:02:50,870
Okay.

56
00:02:50,870 --> 00:02:58,540
And the value of and is zero this is the smallest problem so this will become our base case so it will

57
00:02:58,540 --> 00:03:01,110
return 0 okay.

58
00:03:01,270 --> 00:03:03,390
So Don some of the smaller problem is 0.

59
00:03:03,460 --> 00:03:07,030
And then we have to add the last digit so 0 plus 1.

60
00:03:07,030 --> 00:03:08,390
It will be 1.

61
00:03:08,440 --> 00:03:11,340
Now the answer with the smaller part is 1.

62
00:03:11,440 --> 00:03:13,330
We have to add the last vision which is 2.

63
00:03:13,330 --> 00:03:16,380
So one plus two is three.

64
00:03:16,400 --> 00:03:19,810
Now the answer for the smaller part is 3.

65
00:03:19,820 --> 00:03:21,570
Now we have to where the last digit.

66
00:03:21,590 --> 00:03:24,670
So two plus three is six.

67
00:03:24,700 --> 00:03:28,360
Now the answer for the smaller parties came out to be six.

68
00:03:28,360 --> 00:03:30,200
Now we have to add the last digit.

69
00:03:30,220 --> 00:03:32,990
So six plus four which is 10.

70
00:03:33,080 --> 00:03:36,530
Now the answer for the smaller part came out to be 10.

71
00:03:36,530 --> 00:03:40,730
Now we have to add the lassitude to calculate the bigger problem.

72
00:03:40,730 --> 00:03:41,900
So 10 plus 5.

73
00:03:41,960 --> 00:03:43,210
It will be 15.

74
00:03:43,430 --> 00:03:43,910
Okay.

75
00:03:43,970 --> 00:03:46,800
So I hope by it now do we know the formula.

76
00:03:46,880 --> 00:03:51,680
So if you want to calculate some off and what we have to do.

77
00:03:51,770 --> 00:03:54,230
So some will be a function.

78
00:03:54,230 --> 00:03:59,330
It will take an M but n as input and it will give me the sum of the digits.

79
00:03:59,360 --> 00:03:59,680
Okay.

80
00:03:59,720 --> 00:04:02,100
What I will do I will give the sum function.

81
00:04:02,120 --> 00:04:03,120
The smaller problem.

82
00:04:03,140 --> 00:04:06,460
So this value is and by 10.

83
00:04:06,560 --> 00:04:07,190
Okay.

84
00:04:07,190 --> 00:04:09,790
So this will be what I will do.

85
00:04:09,790 --> 00:04:10,840
I will call.

86
00:04:10,910 --> 00:04:14,900
I will call the same function sum and I will give smaller problem.

87
00:04:14,900 --> 00:04:17,360
I will give it number by 10.

88
00:04:17,390 --> 00:04:18,570
Small problem.

89
00:04:18,590 --> 00:04:20,180
So I am giving this as input.

90
00:04:20,930 --> 00:04:24,410
So some will give me the output for the small problem.

91
00:04:24,410 --> 00:04:27,930
And now what we have to do we have to add the last digit.

92
00:04:28,070 --> 00:04:28,430
Okay.

93
00:04:28,460 --> 00:04:32,550
So I will add the last digit okay.

94
00:04:32,570 --> 00:04:34,280
So I am adding the last digit

95
00:04:37,580 --> 00:04:37,930
okay.

96
00:04:37,940 --> 00:04:39,260
I am writing the last digit.

97
00:04:39,530 --> 00:04:41,910
Now let us write the code and then we will do.

98
00:04:42,020 --> 00:04:44,720
Then they will write in again and we will again make the diagram.

99
00:04:44,780 --> 00:04:45,080
Okay.

100
00:04:46,680 --> 00:04:49,410
So first of all the return day will be in digit.

101
00:04:49,410 --> 00:04:50,960
We have to return the sum.

102
00:04:50,970 --> 00:04:54,070
Let's say the name of the function is someone Lee and what it does.

103
00:04:54,150 --> 00:04:58,420
It will take a number as input and now the base case.

104
00:04:58,440 --> 00:05:00,370
So base case is very simple.

105
00:05:00,540 --> 00:05:02,520
The smallest problem whose solution we know.

106
00:05:02,570 --> 00:05:02,930
Okay.

107
00:05:03,360 --> 00:05:06,630
So the value of any zero obviously the sum will be zero.

108
00:05:07,650 --> 00:05:14,250
Okay so this is our base case Okay so this is base case.

109
00:05:14,310 --> 00:05:16,050
Now it's time for the recursive case.

110
00:05:16,120 --> 00:05:27,730
OK so let's write a recursive case so for the recursive case what will be our small answer so our small

111
00:05:27,730 --> 00:05:29,770
answer will be very simple.

112
00:05:29,770 --> 00:05:35,940
So small answer will be calculate the answer for end by then.

113
00:05:36,030 --> 00:05:36,800
Okay.

114
00:05:36,810 --> 00:05:38,630
And now I want a conclusion.

115
00:05:38,630 --> 00:05:44,430
But so far the calculation but what we have to do we have to find out the last digit first

116
00:05:50,130 --> 00:05:50,640
okay.

117
00:05:50,740 --> 00:05:54,660
So for calculation what we have to do what is our last digit

118
00:05:57,920 --> 00:06:02,440
so calculating the last digit I can do something like this and more tonight.

119
00:06:02,640 --> 00:06:05,400
So with the help of this court I will get the last digit.

120
00:06:05,700 --> 00:06:13,390
And then what I have to do I have to return small answer plus last digit okay.

121
00:06:13,510 --> 00:06:22,910
Now let us call this function let us call the sum function and let us give the value 1 2 3 4 5 as input.

122
00:06:23,120 --> 00:06:28,340
Okay so what we write and set our answer will be 15 okay.

123
00:06:28,350 --> 00:06:36,070
So let's that this file so our answer is coming out 215 our code is working fine.

124
00:06:36,070 --> 00:06:41,660
Now let's try to make the diagram again and see what's happening okay.

125
00:06:41,660 --> 00:06:44,480
So the value of and is one two three four five.

126
00:06:44,480 --> 00:06:50,770
And so this is our value one two three four and five okay.

127
00:06:50,800 --> 00:06:52,810
So this is not close to zero.

128
00:06:52,810 --> 00:06:56,790
So I will come at this line and I will call four and by 10.

129
00:06:56,950 --> 00:07:04,200
So I I will call it 1 2 3 and 4 and this function is working a line number eleven.

130
00:07:04,340 --> 00:07:10,760
This function will go somewhere that line number eleven because it will call 1 2 3 it will wait at line

131
00:07:10,760 --> 00:07:11,540
number eleven.

132
00:07:11,570 --> 00:07:15,140
It will call well it will wait at line number eleven.

133
00:07:15,140 --> 00:07:19,910
It will call 1 and it will wait at line number eleven.

134
00:07:19,910 --> 00:07:21,410
It will call 0.

135
00:07:21,500 --> 00:07:22,420
So what will happen.

136
00:07:22,460 --> 00:07:23,440
It will are done zero.

137
00:07:24,180 --> 00:07:26,150
So it is returning 0.

138
00:07:27,140 --> 00:07:27,400
Okay.

139
00:07:27,440 --> 00:07:34,610
So the small answer small answer is zero then I am calculating the last digit which is and more than

140
00:07:34,670 --> 00:07:35,680
the value of this one.

141
00:07:35,690 --> 00:07:38,540
So one by ten that will be when only.

142
00:07:38,540 --> 00:07:39,030
Okay.

143
00:07:39,170 --> 00:07:41,420
So small answer plus last digit.

144
00:07:41,450 --> 00:07:43,400
So 0 plus 1 which is 1.

145
00:07:43,400 --> 00:07:46,940
So I am returning 1 Okay.

146
00:07:47,100 --> 00:07:50,850
Now here the value of small answer is 1.

147
00:07:51,180 --> 00:07:56,750
Okay so last digit and more 10 so well more than that will be 2.

148
00:07:56,760 --> 00:07:59,410
Okay so the last digit is 2.

149
00:07:59,610 --> 00:08:06,240
And then I am returning the addition of these two so two plus 1 3 I'm returning 3 now the value of small

150
00:08:06,240 --> 00:08:10,580
answer is 3 and then I'm calculating the last digit.

151
00:08:10,590 --> 00:08:12,180
So lost digit is one the.

152
00:08:12,180 --> 00:08:18,270
MARTIN So last digit is came out to be three and then nanometer Dunning the addition of these two so

153
00:08:18,270 --> 00:08:24,670
three plus three which is six so I am returning six small answer is six.

154
00:08:25,000 --> 00:08:26,560
And last digit will we.

155
00:08:26,740 --> 00:08:30,850
So and more ten so that is it is this this will be our last digit.

156
00:08:30,850 --> 00:08:33,650
So last as it is four so six plus four.

157
00:08:33,680 --> 00:08:39,610
I'm returning the addition of these two so I am returning 10 and small answer is 10.

158
00:08:39,880 --> 00:08:43,870
And the last digit will be and more 10.

159
00:08:43,870 --> 00:08:49,060
So last digit will be five and then I am returning the addition of these two so 10 plus five which is

160
00:08:49,090 --> 00:08:49,600
15.

161
00:08:50,320 --> 00:08:50,630
Okay.

162
00:08:50,650 --> 00:08:54,280
So that's how my answer is give out to be 15.

163
00:08:54,310 --> 00:08:54,840
Okay.

164
00:08:54,940 --> 00:08:56,680
So I hope you have understood the code.

165
00:08:56,710 --> 00:08:58,670
So the code is very simple.

166
00:08:59,020 --> 00:09:03,310
We have to write the base case then the recursive case we have to calculate.

167
00:09:03,310 --> 00:09:06,550
We have to call the same function for a smaller input.

168
00:09:06,580 --> 00:09:07,120
Okay.

169
00:09:07,150 --> 00:09:08,910
And then the calculation part.

170
00:09:09,040 --> 00:09:09,540
Okay.

171
00:09:09,610 --> 00:09:12,160
So we are writing the code with the help of PMI only.

172
00:09:12,190 --> 00:09:12,520
Okay.

173
00:09:12,550 --> 00:09:18,280
We are thinking about this diagram late that first we are thinking about this diagram later.

174
00:09:18,280 --> 00:09:23,610
First we are thinking only in terms of PMI we have to think of three steps.

175
00:09:23,630 --> 00:09:30,040
Base case because if case and the calculation part okay if you will write these three steps perfectly

176
00:09:30,130 --> 00:09:32,270
then linear call will definitely work.

177
00:09:32,330 --> 00:09:33,270
Okay.

178
00:09:33,530 --> 00:09:35,310
So I hope you understood this problem.

179
00:09:35,330 --> 00:09:35,750
Thank you.
