Division Math

0 favourites
  • 5 posts
From the Asset Store
Aliens are invading our planet! Solve the math question, and attack the alien with your laser. Covers addition, subtract
  • Hi guys,

    Sorry if this isn't really the correct place for this, but I tried looking online for a solution, and can't find it anywhere, and the things I've seen people pull of with numbers on this forum are incredible.

    I'm trying to set up a system that will work out the division of a number, and so I have Var1/Var2=Var3, but I only want to use numbers that will divide into whole numbers. I have therefore set it up so that it will only show me even numbers, and to do this, I used the expression choose(2,4,6,8...) as the first variable, and then 2 as the second, as that is the only way I can guarantee a whole number.

    I thought about having a system that would divide the first variable by 2, and then generate randomly from 0 to that figure, but I knew I'd end up getting decimals (10/4=2.5).

    Is there an equation that would choose numbers that would generate a whole number as a result?

    Division Example

  • What exactly is your ultimate goal? Is it really just to divide 2 numbers resulting in a whole number. If it is, you've already done that. However, I'm guessing your ultimate goal is something a bit more complex. Could you elaborate a bit?

    When trying to convert numbers with decimals into integers, the following expressions are useful:

    round(x): Round x to the nearest whole number e.g. round(5.6) = 6

    ceil(x): Round up x e.g. ceil(5.1) = 6

    floor(x): Round down x e.g. floor(5.9) = 5

    Taken straight from the system expressions page of the manual.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would like a system that can find all of the whole number divisions of each number.


    10 = (1,2,5)

    15 = (1,3,5)

    28 = (1,2,4,7,14)

    The only save number I can figure out is 2.

    Rounding up or down won't work.

  • Ah, I misinterpreted you original post. You're looking to determine all factors for a number. Well I'm sure there is a more elegant way to do it, but here's one method:



    I use a method called trial factoring. Basically, you take the starting number, take its square route and round it up to the nearest integer(i.e. whole number). Let's call that number "i". Now, try dividing the original number by every integer between 0 and i. For every division resulting in an integer, both "i" and the result are factors. Here's an example:

    Starting number = 22

    The square route of 22 rounded up = 5

    22/1 = 22, so 1 and 22 are factors

    22/2 = 11, so 2 and 11 are factors

    22/3 = not an integer, so no factors

    22/4 = not an integer, so no factors

    22/5 = not an integer, so no factors

    I hope this helps.

    EDIT - Updated capx to use a much less convoluted method for testing for integers, incorporated an array to make sorting easier, and annotated everything. AnD4D

  • The % operator would be useful in this situation. It gives the remainder after a division, so if a%b = 0 then a is divisible by b.

    Here is one event way to do it:

    global number toFactor=28

    global string factors=""

    start of layout

    repeat toFactor times

    system compare toFactor%(loopindex+1) = 0

    --- add loopindex%1 & " " to factors

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