There is really only one "move" in the game. Alice needs to decide who should go first. After that, both players are playing mechanically.
To decide who goes first, Alice finds the least X such that no subset of the available numbers adds up to X. Play will end on turn X, and Alice wants to be the one whose turn that is. So, if X is odd, Alice plays first; otherwise she lets Bob play first.
To easily determine X, Alice uses a Sieve. You're probably familiar with the Sieve of Eratosthenes, used to find primes. Same idea, but with different rules for a different purpose.
Alice writes down the numbers from 0 to the sum of all the numbers on the table, and crosses off 0. Then she takes numbers from the table, one at a time, without replacement. When she takes off the number Y, she crosses off every number that is Y plus some previously-crossed off number. When she has done this for every number on the table, the smallest un-crossed-off number is X.
Notice that this works even if the numbers on the table are not all distinct.
It even works if some of them are negative or zero, except that then Alice's initial list runs from the sum of the negative numbers thru the sum of the positive numbers, and X is the least positive un-crossed-off number.
Improved solution
Assume the numbers on the table are distinct positive integers.
If there were no missing numbers, any sum up to $S(N) = N(N+1)/2$ could easily be gotten, and X would be $S(N) = 1$.
But there are missing numbers. Let's start with an empty table, add numbers to it in increasing order, and after placing each number $n$ compute $S(n)$ = sum of all numbers on the table up to $n$. The question is, is it still true that a player could get any sum up to $S(n)$ from these numbers, assuming it was true for $S(n-1)$ before placing $n$.
Well, if $n \le S(n-1)+1$, then the answer is clearly yes. You could already get any sum up to $S(n-1)$ without using $n$. To get a sum $s$ where $S(n-1) \lt s \le S(n)$, combine $n$ with a combination summing to $s - n$ from the smaller numbers.
Conversely, if $n \gt S(n-1)+1$, then the answer is no. The sum $S(n-1)+1$ is unachievable without using $n$, because it exceeds the sum of the other numbers, and is also unachievable using $n$, because $n$ by itself is already too large.
And that leads to an obvious $O(N)$ algorithm to find X
X = 1
for n from 1 to N
break if n > X
X += n unless n is one of the missing numbers
end
return X
(I assume it's obvious how to do unless n is one of the missing numbers
in constant time, assuming they are given to us in ascending order.)
But if $K$ is much smaller than $N$ we can do better. Suppose we're given the missing numbers in ascending order. Then
MSUM = 0
for each missing number m
MSUM += m
X = m * (m + 1)/2 - MSUM + 1
return X if m >= X
end
return N * (N + 1)/2 - MSUM + 1
This runs in time $O(K)$.
Best Answer
The possible moves are
(1 - n) take n coins of the pile 1 (2 - n)take n coins of the pile 2 (3) take one coin of both piles
The trick in this game is to give your player one of the following kinds of patterns:
(a) N ; N (b) N + 1; N + 2 (c) N + 2; N + 1
Where $N$ represents a multiple of 3 (can be 0. In those positions, the other player cannot win in one round, and we can always answer them in such a way we can give them another piles of those kinds.
We will represent B as the player with the winning strategy, and gives to player A one of the referred positions, wlog (a): if A plays (3), B takes one coin, if A plays (1 - n) or (2- n), the:
if n=1 mod 3, B plays n+1 on the other stack
if n=2 mod 3, B plays n-1 on the other stack
if n=0 mod 3, B plays n on the other stack
In that fashion, B always leaves the game in one of the winning kinds. For (b) and (c), the strategy is similar.
Summing up:
Suppose $N$ is 1 module 3, then A has to use (3) and plays as I explain after, having the winning strategy.
Suppose $N$ is 2 module 3, then A has to use (1 - 1) or (2 - 1), i.e. has to take one coin from a pile at choice. Then plays as I explain after, having the winning strategy.
If $3|N$, then B can always answer