All language subtitles for 15. Amount And Average Of Digits Less Than Given Digit - Solution

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt-PT Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,180 --> 00:00:01,490 All righty. 2 00:00:01,530 --> 00:00:02,520 Right here, right? 3 00:00:02,850 --> 00:00:07,750 All right, so let's start solving these exercise. 4 00:00:08,190 --> 00:00:09,930 OK, guys, are you ready? 5 00:00:10,590 --> 00:00:11,710 Let me make sure. 6 00:00:11,730 --> 00:00:13,620 Yeah, I think you're ready. 7 00:00:13,640 --> 00:00:15,160 The recording is ready. 8 00:00:15,180 --> 00:00:16,950 Everything is set up. 9 00:00:17,250 --> 00:00:17,850 Let's start. 10 00:00:18,690 --> 00:00:24,720 So what we know here is basically that we are going to write down a function, OK? 11 00:00:25,440 --> 00:00:34,190 And these function is going to have basically just one number and one digit. 12 00:00:34,200 --> 00:00:43,200 And we are going to find out, first of all, how many digits simply are less then than this digit in 13 00:00:43,200 --> 00:00:44,100 these given number. 14 00:00:44,100 --> 00:00:51,280 OK, and print the result of the final return thing of the average of the of those digits. 15 00:00:51,540 --> 00:00:56,930 We are going to leave, let's say, for the second step of this solution. 16 00:00:57,480 --> 00:01:05,030 So regarding the first step are let's first of all, define the function signature. 17 00:01:05,370 --> 00:01:08,040 So what do you think should be the function signature? 18 00:01:08,040 --> 00:01:13,110 Shouldn't be void and I don't know, floating point character. 19 00:01:13,120 --> 00:01:14,130 What do you think, guys? 20 00:01:15,510 --> 00:01:21,780 So here you can see that the final result printed is just an integer type, right. 21 00:01:21,810 --> 00:01:29,400 So does it make sense that the function will be of an integer type or maybe instead of the function 22 00:01:29,400 --> 00:01:34,480 should be of a void type since the type of the function is printing? 23 00:01:35,400 --> 00:01:43,260 The answer is absolutely no, because the function is going to return something and this return value 24 00:01:43,260 --> 00:01:46,460 is going to be an average of those digits. 25 00:01:47,070 --> 00:01:53,610 And if it's going to be an average, then chances are high that it's not going to be an integer, but 26 00:01:53,610 --> 00:01:57,870 rather it's probably going to be of a floating point type. 27 00:01:58,150 --> 00:01:59,730 OK, so. 28 00:02:01,000 --> 00:02:10,060 Let's say float will be the type of the function, let's say, I don't know, let's say lower than digit. 29 00:02:10,360 --> 00:02:16,780 OK, lower than digit, the name of the function and the function is going to receive two values in 30 00:02:16,780 --> 00:02:19,480 number and eight digit digit. 31 00:02:20,110 --> 00:02:22,480 OK, so that's the signature of the function. 32 00:02:23,680 --> 00:02:26,620 You know, what should be the next step? 33 00:02:27,220 --> 00:02:28,180 Basically. 34 00:02:29,250 --> 00:02:36,240 What we have to create, let's create some I don't know, let's create counter equals to zero. 35 00:02:36,420 --> 00:02:45,960 OK, and this counter is going to represent the total amount of digits in numbers which are smaller 36 00:02:45,960 --> 00:02:47,100 than the digit itself. 37 00:02:47,580 --> 00:02:52,090 OK, so let's say the following thing are. 38 00:02:52,200 --> 00:02:56,310 So let's start with what do you think should be the best way to go? 39 00:02:56,380 --> 00:02:58,450 What do you think should be the best way to go? 40 00:02:59,040 --> 00:03:05,400 Let's start with the with with with let's start with some basic cases. 41 00:03:05,880 --> 00:03:06,180 Yeah. 42 00:03:06,180 --> 00:03:08,040 I think base cases may be OK. 43 00:03:10,900 --> 00:03:19,030 Let us assume that in this exercise, actually, we can treat two different options, the first option 44 00:03:19,030 --> 00:03:26,830 is the fact that a given number may be also like negative or positive. 45 00:03:26,890 --> 00:03:31,110 OK, we did not specify the name itself should be natural. 46 00:03:31,120 --> 00:03:33,460 So now maybe also positive or negative. 47 00:03:33,880 --> 00:03:40,510 And that's something that we can simply solve by because we do not really care if the sign is positive 48 00:03:40,510 --> 00:03:41,140 or negative. 49 00:03:41,140 --> 00:03:42,930 We just care about the digits. 50 00:03:42,940 --> 00:03:43,200 Right. 51 00:03:43,210 --> 00:03:46,120 We don't care if here will be a minus sign. 52 00:03:46,630 --> 00:03:50,000 So in this case, what we can do is just do the following. 53 00:03:50,020 --> 00:03:56,190 So if nothing is greater than the then zero, that's OK. 54 00:03:56,200 --> 00:04:03,670 But if the is less than zero, then in this case, what we would specify is basically none will be equal 55 00:04:03,670 --> 00:04:06,820 to number multiplied by minus one. 56 00:04:07,450 --> 00:04:15,070 OK, simply reversing or kind of disabling the minus sign so that this way it will be easier for us 57 00:04:15,070 --> 00:04:15,580 to work. 58 00:04:17,280 --> 00:04:27,460 OK, additional thing that we may be considered to be using is the fact that we know that digits are 59 00:04:27,460 --> 00:04:30,250 basically something in the following range. 60 00:04:30,250 --> 00:04:30,670 Right. 61 00:04:30,700 --> 00:04:32,110 They vary from zero. 62 00:04:32,110 --> 00:04:35,940 One, two, three, four, five, six, seven, eight, nine. 63 00:04:36,310 --> 00:04:37,030 And that's it. 64 00:04:37,240 --> 00:04:40,880 OK, that's the range that the digits vary. 65 00:04:42,070 --> 00:04:45,700 So the lowest digit here is zero. 66 00:04:46,250 --> 00:04:48,570 OK, so that's also fine. 67 00:04:49,090 --> 00:04:55,290 And what we have to do now to start doing is doing the following thing, the following thing. 68 00:04:55,300 --> 00:04:59,020 As long as NUM does not equal to zero. 69 00:04:59,320 --> 00:05:04,900 OK, as long as NUM does not equal to zero, we are going to ask the following question. 70 00:05:05,500 --> 00:05:18,280 We are going to ask if num modulo 10, which basically says take every time the rightmost digit in a 71 00:05:18,280 --> 00:05:25,750 number OK in a given them and ask if it's less than digit if that's the case. 72 00:05:26,020 --> 00:05:31,040 OK, if that's the case, what we are going to do is to say counter. 73 00:05:31,900 --> 00:05:33,610 Plus plus. 74 00:05:33,880 --> 00:05:35,560 OK, Gunta plus plus. 75 00:05:36,760 --> 00:05:41,470 And right afterwards we are going to say that number will be divided by 10. 76 00:05:41,980 --> 00:05:42,380 OK. 77 00:05:42,400 --> 00:05:43,750 Is everything clear so far. 78 00:05:43,780 --> 00:05:45,550 Nothing special, nothing complicated. 79 00:05:46,090 --> 00:05:51,590 Simply taking into account that in every iteration. 80 00:05:51,620 --> 00:05:55,720 OK, we will take this nominee to read over and over again, again, again. 81 00:05:55,720 --> 00:06:02,000 Until we reach that fact that NOM does not have any digits at all, meaning it's zero. 82 00:06:02,890 --> 00:06:10,690 So if NUM module 210 is less than digits, calendar plus plus num equals to num divided by ten. 83 00:06:10,690 --> 00:06:16,390 Meaning we start with this number which I give to is less than three, maybe the counter goal plus plus 84 00:06:16,660 --> 00:06:19,080 then we divide these num by ten. 85 00:06:19,090 --> 00:06:22,030 We are just left with one three five seven. 86 00:06:22,570 --> 00:06:26,650 Then we do the situation again and again and basically that's it. 87 00:06:26,920 --> 00:06:27,170 OK. 88 00:06:27,220 --> 00:06:31,390 And finally what do we have to do is simply print out. 89 00:06:31,720 --> 00:06:39,790 OK, print out our total amount of digits in num, ok. 90 00:06:39,790 --> 00:06:41,500 Or basically in percentage the. 91 00:06:43,220 --> 00:06:53,750 Total amount of digits in percentage is less than percentage, the total amount of digits in R equals 92 00:06:53,750 --> 00:06:57,020 two equals two percentage, OK. 93 00:06:57,800 --> 00:07:04,250 So now we are going to specify these for a percentage now and here we are going to specify specified 94 00:07:04,250 --> 00:07:05,240 as counter. 95 00:07:05,750 --> 00:07:11,630 So simply saying the printing operation is pretty much complete. 96 00:07:11,660 --> 00:07:12,440 What do you think? 97 00:07:13,250 --> 00:07:15,500 I think that it is a complete. 98 00:07:16,740 --> 00:07:23,730 And one last thing that maybe we have to take into account is we have to take it into account is the 99 00:07:23,730 --> 00:07:31,440 second thing that these function should return the average of those digits that are less than digit. 100 00:07:31,980 --> 00:07:37,990 So if we want to find out what should be the average of these digits. 101 00:07:38,250 --> 00:07:44,940 So one thing that you have to consider using is basically to sum up everything so far. 102 00:07:45,000 --> 00:07:46,530 OK, so how do you do it? 103 00:07:47,270 --> 00:07:50,280 Basically, you do it in the following way. 104 00:07:50,280 --> 00:07:51,630 So you say like this. 105 00:07:51,640 --> 00:07:58,760 So let's say I go into some OK, total sum, total sum equals to zero. 106 00:07:59,220 --> 00:08:03,150 And here on every duration, OK, on every iteration. 107 00:08:03,360 --> 00:08:10,590 We are also going to like to take the digit, the rightmost digit and added to this sum. 108 00:08:10,770 --> 00:08:14,610 OK, so now what do you tell the rightmost digit. 109 00:08:15,400 --> 00:08:19,940 You know, once we are done with this step, we can simply return. 110 00:08:20,230 --> 00:08:21,330 What can we return? 111 00:08:21,730 --> 00:08:27,880 Total sum, total sum divided by counter. 112 00:08:28,160 --> 00:08:29,920 OK, and what do you think? 113 00:08:30,070 --> 00:08:31,690 Is this OK or not? 114 00:08:31,910 --> 00:08:34,990 We basically should also add the casting. 115 00:08:36,050 --> 00:08:40,980 OK, guys, so that's pretty much it for this video. 116 00:08:41,000 --> 00:08:47,780 I think that everything is correct here, if I'm not mistaken, on any any line, let me know if you 117 00:08:47,780 --> 00:08:51,650 execute the main function for it and everything works as expected. 118 00:08:52,070 --> 00:09:00,950 Of course, there are also additional options to you to, like, kind of solve it and to treat some 119 00:09:00,950 --> 00:09:07,390 base case like, I don't know, int num num equals to zero as well as the digit equals to zero. 120 00:09:07,430 --> 00:09:13,850 What should be what should happen in this case or basically if the digit equals to one in num equals 121 00:09:13,850 --> 00:09:14,600 to zero. 122 00:09:14,760 --> 00:09:17,150 OK, so how should you treat this case. 123 00:09:17,930 --> 00:09:20,690 And basically that's something I'm leaning up to you. 124 00:09:20,690 --> 00:09:24,350 I think you can also added on your own and. 125 00:09:24,440 --> 00:09:24,840 Yeah. 126 00:09:24,860 --> 00:09:31,180 So you simply regarding the printing, we understood everything correctly regarding the average. 127 00:09:31,190 --> 00:09:38,330 We simply found out the total sum of all the digits that satisfy this condition, that the rightmost 128 00:09:38,330 --> 00:09:41,260 digit in NUM is less than the digit itself. 129 00:09:41,510 --> 00:09:43,910 And we summed up all of these digits. 130 00:09:44,330 --> 00:09:52,100 And finally, we are if we want to find the average, we took the total sum and we divided it by the 131 00:09:52,100 --> 00:09:54,470 total counter of all the elements. 132 00:09:55,130 --> 00:09:56,870 So there you go, guys. 133 00:09:56,900 --> 00:09:58,050 Thank you so much for watching. 134 00:09:58,070 --> 00:10:00,950 And until next time, I'll see you then. 12318

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.