# I have to derive my own equation, I need help

1. Mar 29, 2005

### eNathan

I am programming a software which generates random (or close too) numbers. I am adding a multi-player feature to it. I ask the user how many players there are (variable P'), and how many turns in a row each player gets (variable e, for every). I also know the total amount of global turns that have taken place in the game (variable T).

Each player gets there turn via least to greatest. Player "1" goes first, and gets to play for "e" amount of times. Each time any player takes a turn, variable "T" increases by +1. How do I know who's turn is (variable p) given the values of P', T, and e? I make algerbra equations all the time, but I have been struggling with this for days and I just cant seem to get it. I hope somebody here is good enough at mathematics to derive an equation from this. I know you have to use the Fix() function in it, and you probably have to divide T by P' somewhere. But I do not have the equation I will draw a chart of how the game will fold out.

P' = 2 (it's a two player game) e=1 (Each player gets to play one time in a row)

remember...T = Total turns in the game p = Who's turn it should be

T p
-------
1 1
2 2
3 1
4 2
5 1
6 2
7 1

P' = 2 (it's a two player game) e=2 (Each player gets to play two times in a row)

remember...T = Total turns in the game p = Who's turn it should be

T p
-------
1 1
2 1
3 2
4 2
5 1
6 1
7 2

P' = 2 (how many players there are) e=3 (Each player gets to play three times in a row)

remember...T = Total turns in the game p = Who's turn it should be

T p
-------
1 1
2 1
3 1
4 2
5 2
6 2
7 1

again, I need to know p with only knowing "P'", "T", and "e". If I can draw a diagram of it on paper, I know it can be done mathematically

Thank you very much

2. Mar 29, 2005

### Moo Of Doom

A bit trickier than I first thought...

$$p=ceiling(\frac{T}{e})+P-floor[\frac{ceiling(\frac{T}{e})+P-1}{P}]*P$$

where ceiling(x) is the least integer greater than or equal to x, and floor(x) is the greatest integer less than or equal to x.

Last edited: Mar 29, 2005
3. Mar 29, 2005

### eNathan

ASCII = p = Ceil(T/e)+P-1-Floor((Ceil(T/e)+P-1)/P)*P+1
I hope lol I am going to try it right now :)

4. Mar 29, 2005

### eNathan

nope, that one gave some very upredictable results. Your first one was closer to working, unless...I typed the equation wrong. Is this right?
p = Ceil(T/e)+P-1-Floor((Ceil(T/e)+P-1)/P)*P

Last edited: Mar 29, 2005
5. Mar 29, 2005

### Moo Of Doom

You don't need the +1-1 in there... I cleaned that up a little while ago. It came from the method I was using.

I think that equation should theoretically work. Try some cases by hand.

Let's try P=3, e=2, T=7.

T p
1 1
2 1
3 2
4 2
5 3
6 3
7 1
8 1

So, p should equal 1.

ceiling(T/e)=ceiling(7/2)=4
floor((4+P-1)/P) = floor(6/3)=2
2*3=6
4+3-6=1
Thus Ceil(T/e)+P-Floor((Ceil(T/e)+P-1)/P)*P = 1, like it should.

Not sure what the problem is...

6. Mar 29, 2005

### eNathan

but when you try that with higher numbers, everything goes wrong. I think I can fix your equation if I think about it enough, but I have to get some sleep. I will give you my results.

When T = 1, p = 2
When T = 2, p = 2
When T = 3, p = 3
When T = 4, p = 3
When T = 5, p = 4
When T = 6, p = 4
When T = 7, p = 5

7. Mar 29, 2005

### Moo Of Doom

I'm not sure what's going on then.

Ceil(T/e)+P-Floor((Ceil(T/e)+P-1)/P)*P works for every number I try. Maybe order of operations isn't followed?

Try temporary variables, like
a=T/e
b=Ceil(a)
c=(b+P-1)/P
d=Floor(c)*P

p=b+P-d

8. Mar 31, 2005

### eNathan

Sorry for the late reply, but yes that did work. Thank you very much, now I can finish my software :)