Please view comments to see how it is not a duplicate.... I am looking at it from a CPU perspective.

If there are 23 coins that are on a screen, and there are two players and you get to pick if you go first or second, how can you guarantee that you will not get stuck with picking the last coin? Basically, the objective is to force the other person to pick the last coin.

every turn you can pick 1 or 2 coins

I think half of the answer is in how many coins to pick in the first turn.


1 Answer 1





Take 1 coin


Take the opposite amount of coins that the other player takes (so after two half-plies 3 coins are taken)


After 15 half-plies, there will be $23-1-7\times3=1$ coin left, and it will be your opponent's turn


They have to take the last coin

If you want to play with a computer, here is some Python code (only guaranteed to work in this particular instance):

while n>0:
    print('Current number of coins:',n)
    print('I choose:',(n-1)%3)
    print('Current number of coins:',n)
    while True:
        i=input('Pick a number: ')
            if n>=j==1 or n>=j==2:
            raise NameError
            print('Invalid input')
    print('You chose:',j)
print('There are no coins left')
print('You lose')

  • $\begingroup$ That works. But, isn't another solution taking 2 and then attempting to form pairs of 2 each time. So, take 2 and then playing the same amount of coins as the opponent. $\endgroup$
    – G.B
    Commented Oct 16, 2017 at 22:12
  • $\begingroup$ If the opponent takes 1 each time, until you get down to 3, then the opponent takes 2, there is one coin left and you are doomed. $\endgroup$
    – boboquack
    Commented Oct 16, 2017 at 22:14
  • $\begingroup$ what happens if I pick 2 coins to start. What is a guaranteed way that I can lose? $\endgroup$
    – G.B
    Commented Oct 23, 2017 at 22:54
  • $\begingroup$ i was wondering how a cpu can play perfectly $\endgroup$
    – G.B
    Commented Oct 23, 2017 at 23:08
  • $\begingroup$ @G.B if you want to lose, pick two coins at the start, and take the opposite to what the opponent takes. Then you will go 23 - 21 - ? - 18 - ? - 15 - ... - 3 ? - 0. $\endgroup$
    – boboquack
    Commented Oct 23, 2017 at 23:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.