How do I calculate the factors of a number?

0 favourites
  • 3 posts
From the Asset Store
Jump on numbers in the proper order and reach the sun!
  • 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.)

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)