I have a line of code in my program that checks if a number is divisible by several numbers.
However, the way I'm currently using is extremely inefficient and ugly.
Currently it looks like this:
if(x % 1 == 0 and x % 2 == 0 and x % 3 == 0)etc. for several other numbers. I was hoping someone would teach me how I can pull out a long chain andand help me replace it with something that makes more sense, so it would look like this:
if(x % a[1,2,3] == 0)
Is this possible, and if so, can someone help me?
EDIT: x% 1 == 0, x% 2 == 0, etc. This is not a complete equation. I check a lot more than% 1,2, and 3. I'm looking for a solution that can take, say, 1 to 15. That's why I don't use x% 6.
source
share