# Program formula given categories and num total?

• Oct 14th 2012, 11:17 AM
Brightnail
Program formula given categories and num total?
I know this is unorthodox. Not even sure this is the correct forum.

I have an algorithm, I believe, that i am in need of. I'll try to explain.

The following number assignments will constantly change, so the formula needs to be able to adapt.

max = 50

I have three categories:

Local, National, International

Each will have a number assigned depending on a number of factors. So, for example. The *max* number above is the display on a page of the data in the three categories.
Now, if I am only allowed 50 per page and each of those categories can have *n* amount and must be in the order supplied: Local shows all of its content, then national, then international. When one cat is exhausted the next category continues.
Could have the remnants of one cat end, and one start up on the same page.

So,

max = 50

Local = 149,
National = 112,
International = 40

What would be the formula that which gives me the proper display request. I will have knowledge of the current page (page they request). We'll call that currPage.

(Local - (max x (currPage - 1)) / max >= 1 --> request 50 Local if true;
(Local - (max x (currPage - 1)) / max < 1 --> request the Modulus amount and then start into National

I am just at a loss here on how to construct this sort of display. This is a programatic sort of thing.

so, ultimately the display or logic would give me:

page 1:
Local = 50

page 2:
Local = 50

page 3:
Local = 49
National = 1

Page 4:
National = 50

Page 4:
National = 13
International = 37

Page 5:
International = 13
• Oct 15th 2012, 01:13 AM
chiro
Re: Program formula given categories and num total?
Hey Brightnail.

What kind of environment are you running in? Excel? C++? VB?
• Oct 18th 2012, 06:18 PM
Brightnail
Re: Program formula given categories and num total?
Javascript :-)