 What's up guys my name is Michael and welcome to my YouTube channel today. We're gonna do another lead code challenge Self-dividing numbers a self-dividing number is a number that is divisible by every digit It contains for example 128 is a self-dividing number because 128 mod 1 is equal to 0 128 mod 2 is equal to 0 128 mod 8 is equal to 0 So it is divisible by every number it contains every digit it contains Also a self-dividing number is not allowed to contain the zero digit zero Given a upper and lower bound output every single possible self-dividing number including the bounds as possible This is pretty basic you guys try to do this on yourself on your own and Come back to me when I when you're done Okay, try to do this on your own if you can't figure it out in one or two hours then come back to this video but essentially the algorithm is is that You're gonna go through every number between left and right Inclusive, okay, and you're gonna check if it's a self-dividing number That is it's divisible by every of its digits Okay, and if it is then we add it to the array. We're returning and then When we go through from left to right once we're done with the right one, we just return the array That's essentially the algorithm. Yeah That's how you would do it come back when you implemented that and then We'll see you if your solution is like my solution. So yeah Okay, so first whoa Hold up guys hold up my bad Hold up Okay, so first, how do we do this? Well first you need to create an array that you got a return that has all the Self-dividing numbers so this is gonna do it's I'll call it to return for now, but yeah, then what do we got to do? We got well we got to go through every single value from left If it's less than we're including right, so it's that's why it's left and equal to go through every value between left and right and then if is self-dividing Passing if whatever value we're checking it's self-dividing. We're gonna add it to return dot pushback I Then after that we're gonna return To return okay, so then that's essentially the algorithm now. We need to create a method called Is self-dividing? We're gonna pass in a value of I so how do we check if it's self-dividing? Well a self-dividing number is a number that's divisible by every single to every digit in contains so first we need to Essentially Let me think how do I say this? do-do-do-do-do-do We have to go through We have to get every single digit And then mod it Get every single digit mod it and if it equal if it doesn't equal to zero Then we return false Okay, and we're gonna do that for every single digit. So how do we do that? We're gonna do while While I is greater than zero Okay We're gonna do I is okay. Okay. How about instead of using I I'll use an actual number So let's change I do like numb so that I don't like the variable I so my eyes greater than zero We're gonna take number and we're going to divide number by 10 So if you divide by 10 So let's say 128 you divide by 10 then you get one two 28 28 to yeah, so that gets you If you were to divide a number by 10 You get this one two that's the remaining Okay, and now what we want is we want the remainder Want to mod by 10 to get the last digit so that we to get eight and then two they want So I'm gonna take all a number called remainder It's gonna equal to numb mod 10 Okay, so this is gonna get the remainder now What we need to do is we need to check if the original digit is Able to mod by The remainder and if it's equal to zero then we continue if it's not equal to zero then we return false Okay, so in order to do this we need to create another variable We're gonna call this original and this is going to equal to whatever value we passed in the original number before we went through this while loop Okay, so let me call this original. All right now. We're gonna check if original Mod Remainder is not equal to zero Okay, then that means we return false we also have to check or The remainder is equal to zero because if the remainder is equal to zero is not allowed to contain the digit zero So we got to return false. All right. This is good. Basically going to go through every single digit in this Ray if for every number and then it checks if it divides it mods it equal to zero, okay It doesn't go to zero returns false After this loop is finished That means it must have None of that means none of them have returned It had not returned false. We're gonna return true. Okay, none of them all of them had been able to divide by Mod by zero mod by remain. So they were all Divisible by each digit. Yeah, this is should work if it doesn't work then I Don't know There's must have been a compiler or something happened. It's basically how you would do it. Let's see what happens Runtime error. What is the difference? divisible division by zero Okay, so you can't do this we got to do this first. It's equal to zero in return There's the effects of It's called Shortcutting I think something called short cutting where it checks the left side first then checks the right side. Okay, so this is working Now we submit and it got accepted. So that's basically how you would do this. Yeah, I don't think there's any other way Let's see solution. Oh, yeah, okay, so there's only brute force They don't have anything else That's basically how you do it right com subscribe. I hope your solution looked something like mine I'll check you guys later. Peace