Jump to content
  • Advertisement
Sign in to follow this  
KillerkoUK

how to get the same repeating numbers for any of my imput number?

This topic is 1448 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have input numbers:

 

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13.... etc

 

I would like to get output for each of these nunbers to be:

 

1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2... etc

 

so for my input 12 i wanna get 4 and for 13 it would be 1 and so on

 

is there any simple way how I could get that?

 

for example 13 - ( int(13/4) * 4 )  is 1

that works for 14 or 15 too, but unfortunately not for 12 or 16 as i will get 0 which is wrong

 

Share this post


Link to post
Share on other sites
Advertisement

You want the modulo operator, which essentially gives you the remainder of a division (although there are some subtle differences for negative numbers)

 

It might look like 'mod' or '%' depending on the language.

 

For your specific case, try: ((n - 1) % 4) + 1

Edited by C0lumbo

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!