All language subtitles for 17. Advanced - Even Digits Sum [OPTIMIZED & MINIMIZED]

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
ceb Cebuano
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
hmn Hmong
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
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
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 Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
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

Original subtitles

So what is going on, guys, and I've just looked at the previous exercise and and the previous solution

that was provided.

And I have been thinking to myself as to can we improve this solution?

Yes or no?

I mean, like it seems to be working just fine by splitting up every time for a smaller sleep problems

and on every recursive call, taking some rightmost digit and comparing it with the results so far.

And although this work just works just fine, I have been thinking if we can optimize it a little bit

and reduce the number of lines of code that we use here in order to make these recursive call recursive

function much smaller in code.

So what I want you to think about is, first of all, these works just fine.

Now we can try to think about how we can optimize it and minimize it.

So a result so far, if the result so far is one right?

So it will stay one if basically if we take a look at the right, most digit.

So if the right, most digit will be even right, this indicates that the right most digit still remains

even right, then the results so far will remain the same.

And also, the results so far will have remained the same in this case, whenever the results so far

is zero.

So if the result so far was even or odd, OK doesn't really matter.

And of the right most, the digit in this recursive call was what was even then the results so far,

and this function will return the same value that it had previously.

So if it was one, it still will will remain one.

And if it was zero, it still will remain zero.

OK, so what I'm trying to say is that the results so far, maybe even.

Plus, the even right most digit will result in an even, and if it was odd plus in even which is the

right most digit, it will still remain odd.

OK, so it will not change the status.

On the other hand, if we know that these else are relates to the fact that they're right, most digit

is odd.

Then if the result so far was one, it will change its status, OK?

It will become zero, because if we know that the result so far is odd, and if we know that the result

so far is even and we know that the right most digit is odd, then odd plus even will result in an odd

value.

And that's the same also for here, if it was an order value, right?

The result so far was a sum that is odd.

Plus, this else relates to the right most digit.

When it's odd, then odd plus order will equal to even meaning we will need to change the status.

The results so far, the return value from this function again.

So what we'll try to do is basically to minimize this task, OK, and make it a little smaller with

much less lines of code.

OK, that's what I'm going to show you right now.

So instead of using it like this, what we will ask is the following question we will ask if the right

most digit like this, if it's the case right, then what we will need to do is simply too.

Okay, I'm trying to build this thing together with you.

If that's the case, right?

If that's the case, then what we need to return is what do you think is just the results so far?

Return result?

So far, that's it.

Because since the right, most digit is in even one.

OK.

There is no reason for us to change it.

OK, but if it's not, then we will need simply to return what?

We will simply need to return.

Let me get it right here.

We will simply need to return, not results so far.

So what I've written here and I'm not finished yet.

I said that if the rightmost digit will be even then returned the results so far because this does not

affect the overall sum.

If it was, if it was an even some, it will still remain even.

And if it was odd, it will still remain odd.

On the other hand, if the right was the it was odd, then switch from the results.

So far, OK, not means here.

Basically, if we use just ones and zeros.

So if the result so far was zero, this not will turn it into one.

And if the results so far was one, the Senate will change it to zero.

OK, awesome.

So now what I'm also going to do is to say that let's not using these results so far are variable.

And instead of these results so far right, we know that this is the value.

So instead of using it, we will simply change instead of results so far will specify the recursive

call.

OK.

It's just the same.

OK, so you see how the recursive call function, the recursive function has got much smaller, although

I do not recommend to make this version right from the beginning.

But after you practice the little bit of your exercises, I suggest creating the first initial version

that we had previously OK with all these lines of code and then ask yourself a simple question Can you

optimize this solution?

Can you minimize the number of lines of code and the number of variables created in the process of the

recursive function?

And the answer is yes.

OK.

And now I want to also continue optimizing it.

OK.

I want to say that instead of using these four lines of code.

What I will use is the following line of code.

I will say return return in modular to.

Equal to zero right, or B or C, let's use it like this, OK, if an equal to zero, then we will return

one.

Right?

That's what we will return.

Otherwise, we will return zero.

So this line of code I simply am showing, I'm simply showing you a little another option to do that.

OK, so return and modular two equals to zero.

So basically, both of these two versions, these four lines and this one one on one line, they represent

the same thing.

So we ask if that's the case.

Question mark, then return one.

OK.

The result for this condition is true.

Then return one, otherwise return zero.

OK, so that's basically what we have here.

OK, and we can also further optimize it.

Instead of saying it like this, we can say if and modular two.

Does not equal to zero, then returns zero in one, I'm simply switching places.

OK, follow up this like line by line, OK?

I didn't do anything wrong.

I just switched the places between the true result for this condition and the false result for this

condition.

And what I can ask is this simple question.

I can also remove this not equal to zero, because that's how this condition is interpreted.

It return in modular two.

If that's the case, and if it doesn't equal to zero, then return zero, otherwise return one.

Okay, so that's just short version of writing the code.

And finally, I will do also the same here.

I will say this line of code, I will say return, and I will say this part OK, if this part does not

equal to zero.

OK, so if that does not equal to zero, then return this part.

OK, if there's an integral to zero on this one and otherwise return this option.

That's it.

So these four lines of code are equivalent to this line of code.

So I will remove it in.

Finally, the final version for these function looks like this.

OK, so that's very nothing to do to read it first.

But actually, that's the answer.

That's the recursive function call optimized, minimized in lines of code.

And yeah, OK.

So you can also make sure that I've done everything correctly here by simply testing out with some examples

and hopefully because the hour is late and make sure that it works exactly as you expect.

And I really do recommend to start with the basic option that we've solved in previous videos.

And only when you feel more confident to start trying to take a look at how you can reduce the number

of lines of code and make it look like this, OK?

So yeah, this is it for these video guys.

Thank you so much for watching.

Keep on practicing.

Let me know what you think of it.

And until the next time, I will see you in the next videos by.

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