I'm impressed you seem to be really very good in math! :O!!
I can't verify what you wrote because it seems like rocket science to me.
But here's the generic approach to solving such problems. Mostly I'm right on this one but keep in mind that I'm a noob.
So you have a pile of N coins. Alice and Bob take coins from the pile. When Alice and Bob take coins from the pile, we are basically subtracting from the pile.
Suppose Alice just finished taking 4 coins from the pile leaving 2 coins, and Bob needs to take 4 coins. 2-4 would give -2 which is not possible, which I think you understood as well.
Also keep in mind that how many coins is taken from the pile is dependent on this formula k^i, which again, you probably already know.
You could probably do this with math with little computation, but the general idea for solving such problems would be to use control statements (sometimes recursive functions also).
So how about something like this?
(pseudo code)
1 2 3 4 5 6 7 8 9 10 11 12
|
current turn = Alice's
for (int i=0, Coins in Pile > 0, i++)
if (Alice's turn)
winner = Bob
current turn = Bob
else
winner = Alice
current turn = Alice
Coins in Pile = Coins in Pile - (k^i)
|
Hopefully if there are any improvements, somebody else can mention it.
I'm sure you will understand most of the code.
For k^i you can use pow() which is a function from cmath or, you could also write a for-loop (how would you do that??) but I'm not saying you should write a for-loop. Better rely on pow().
By the way we're using a for-loop over a while loop because we can use "i" the iterating variable, we could have also used a while loop it's the same thing.
Okay mostly you probably could understand everything but you might get confused in one detail - why we're assigning the winner to be the person who played last turn. If you do then I think you should think about it yourself ;^), that's how you learn and that's how you build your logic!