How do I calculate the factors of a number?

Get help using Construct 2

Post » Sun Jun 07, 2015 7:36 pm

Is there a simple way to break apart a number into its factors? And possibly isolate them?

For example, if I input the number 12, it'd output 1, 2, 3, 4, 6, or 12.

What I'm trying to do is detect when a number is, say, divisible by 3. So I could crack the number into its factors and if the second or third factor is a 3 I'm golden. If there were a math expression like "factor(x, y)" where x = the number to deconstruct and y = the factor to pull out I'd be luckier than a box of breakfast cereal, but I couldn't find anything like it in the System Expressions section.

Thanks in advance!

(I dug through the manual and did some searches through the "How Do I...?" section and I couldn't find a solution, probably because of how often the word "factor" is used outside of math.)
B
24
S
6
G
6
Posts: 17
Reputation: 4,458

Post » Sun Jun 07, 2015 8:02 pm

You can use the modulo (%) operator to determine divisiblity. Modulo returns the remainder of division. So if the result of the expression (n % 3) equals zero, you know that the number n is divisible by 3.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,126

Post » Sun Jun 07, 2015 8:11 pm

Oh, excellent! I got stuck trying to approach the solution from the wrong angle. Factors! Psha! XD

Thanks a lot, linkman! This certainly does the trick. :)
B
24
S
6
G
6
Posts: 17
Reputation: 4,458


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 11 guests