1
$\begingroup$

This question already has an answer here:

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.

$\endgroup$

marked as duplicate by boboquack, Alconja, Jamal Senjaya, JonMark Perry, Glorfindel Oct 17 '17 at 9:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1
$\begingroup$

Go:

First

And:

Take 1 coin

Then:

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

So:

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

And:

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):

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

$\endgroup$
  • $\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 Oct 16 '17 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 Oct 16 '17 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 Oct 23 '17 at 22:54
  • $\begingroup$ i was wondering how a cpu can play perfectly $\endgroup$ – G.B Oct 23 '17 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 Oct 23 '17 at 23:22

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