Number Divisibility Rules Snippet
Armelline
Member, PRO Posts: 5,371
Hey all,
I've just been fine-tuning the last bits of a new game and a part of the game has actors spawn every other "point" scored. Upon testing, though, I found that this felt too frequent. This led me to test every 3rd, every 4th, every 5th.
In doing so, I found I had to calculate if a particular number was divisible by 2, 3, 4, 5, 6 etc.
I thought I'd share the (very simple) methods I used in case they're of help to anyone. (Though most here will be able to work this out for themselves, easily enough.)
Etc. for higher numbers.
Would love to get rid of the or's needed for 3 and 5 so shout if you know a better way!
I've just been fine-tuning the last bits of a new game and a part of the game has actors spawn every other "point" scored. Upon testing, though, I found that this felt too frequent. This led me to test every 3rd, every 4th, every 5th.
In doing so, I found I had to calculate if a particular number was divisible by 2, 3, 4, 5, 6 etc.
I thought I'd share the (very simple) methods I used in case they're of help to anyone. (Though most here will be able to work this out for themselves, easily enough.)
Divisibility Rules:
Divisible by 2:
If game.attribute%2 = 0 then true
Divisible by 3:
If (game.attribute/3)%2 = 0 or (game.attribute/3)%2 = 1 then true
Divisible by 4:
If (game.attribute/2)%2 = 0 then true
Divisble by 5:
If (game.attirbute/5)%2 = 0 or (game.attribute/5)%2 = 1 then true
Etc. for higher numbers.
Would love to get rid of the or's needed for 3 and 5 so shout if you know a better way!
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
Comments
Any chance a mod can move it to the Working with GameSalad forum?
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
Divisible by 2
If mod(game.attribute,2) = 0
Divisible by 3
If mod(game.attribute,3) = 0
Divisible by 4
If mod(game.attribute,4) = 0
Divisible by 5
If mod(game.attribute,5) = 0
and so on
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
: )
Divide the mystery number by 5 - then check the result is equal to ceil(result) - if it is, then it's divisible by 5.
So basically divide the mystery number by the check number and see if the result is a whole number, if it is a whole number then the mystery number is divisible by the check number.
(mod(self.myNum,10)==0)and(10)or(mod( self.myNum,9)==0)and(9)or(mod( self.myNum,8)==0)and(8) or(mod(self.myNum,7)==0)and(7)or(mod(self.myNum ,6)==0)and(6)or(mod( self.myNum,5)==0)and(5) or(mod(self.myNum ,4)==0)and(4)or(mod(self.myNum,3)==0)and(3)(mod(self.myNum,2)==0)and(2)
Is the value = (ceil(value/X))*X ?
If the they are the same, then the value is divisible by X.
:-B 8-X <:-P
)
Link: https://www.mediafire.com/?255pxd8757g4a0x
Enter a value - and it will quickly check whether it is divisible by every number from 1 to 950 (I couldn't fit any more on the screen !) - the green numbers are numbers that your input value is divisible by ('hits').
To check divisibility this project uses: is the value = (ceil(value/X))*X
Obviously big numbers at the input stage result in prettier pattens with lots of 'hits'.
Youtube: lots of small type: Hit that 720pHD button or risk blindness :-B
Link: https://www.mediafire.com/?j7b8bj3n728i57u
And no, you haven't taken it too far - there is still room for going up to 2583 in your demo...
*(or 'Tony', Tony is also free, and Barbara, so basically 'interpolate', Tony or Barbara)**
**(actually 'change attribute' has also just become free, he was killed by one of those robot spider things, may 'change attribute' rest in peace)***
***(oh, nearly forgot, we don't currently have a 'Mary' either, so 'interpolate', Tony, Barbara, 'change attribute' or Mary, your choice, no pressure, but we must have an answer by Monday)