반응형
This function should test if the factor is a factor of base.
Return true if it is a factor or false if it is not.
About factors
Factors are numbers you can multiply together to get another number.
2 and 3 are factors of 6 because: 2 * 3 = 6
- You can find a factor by dividing numbers. If the remainder is 0 then the number is a factor.
- You can use the mod operator (%) in most languages to check for a remainder
For example 2 is not a factor of 7 because: 7 % 2 = 1
Note: base is a non-negative number, factor is a positive number.
Solution:
SELECT
id, (base % factor = 0) AS res
FROM
kata
Result:
id | res |
1 | true |
2 | true |
3 | true |
4 | true |
5 | false |
6 | false |
7 | false |
8 | false |
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
Grasshopper - Terminal game move function (0) | 2022.05.29 |
---|---|
Easy SQL: Cube Root and Natural Log (0) | 2022.05.27 |
SQL Basics: Maths with String Manipulations (0) | 2022.05.25 |
SQL Basics: Simple MIN / MAX (0) | 2022.05.24 |
SQL Basics: Simple JOIN (0) | 2022.05.23 |