I have some code where, if a user has referred X number of people, he will get X number of credits.
For example, referring 2 people = 1 credit. 4 people = 2 credits, and so on.
However where this gets tricky is, the numbers can be changed so he gets 1 credit per person, or 1 credit per 3 people, 1 credit for 5 people, etc.
If he gets 1 credits for 3 people, and he has referred 5 people, then I would like him to receive 1 credit, and have it stored that he still has 2 people for whom he didn't get any credits. So the next time he refers someone, it is 2 + 1 = 3, and he gets a credit.
My question is,
Given X = Number of people he needs to refer for 1 credit, and Y = Number of people a user has refered,
(So X might be 3, as in 3 people per credit, and Y might be 6, in which case he should get 2 credits)
1) What's a straightforward formula or function which will X and Y, and return the number of credits which should be given to that person, and
2) Which will also give a remainder for the credits which can't be awarded yet. E.g if X is 3 and Y is 5, the credits would be 1, and remainder would be 2, so with the next referer Y will become 3 again and the user would get 1 credit?