Ann and Bob play alternately on a pile of chips. On each play, either 1, 2 or 3 chips can be removed except if the number of chips is a prime number. In that case either 1, 2, 3, 4 or 5 chips can be removed.The person, who removes the last chip is the winner. There are 100 chips on the pile. Ann starts. Determine a winning strategy for one of the players.

  • $\begingroup$ It could work without a trivial answer if primes didn't allow all the moves for compounds. $\endgroup$
    – Nautilus
    Commented Jul 24, 2019 at 15:19

1 Answer 1


It seems like you force a win if you can leave behind a multiple of 4. So the first player is guaranteed to lose because he cannot leave behind a multiple of 4. Whatever amount player 1 takes (x), player 2 should take 4 - x.

Here's a little Python program to test it yourself:


And here's C++ code written by user @im_so_meta_even_this_acronym


  • $\begingroup$ Would you mind adding my code for C++ users? :) ideone.com/SfMHqC $\endgroup$
    – sunfishho
    Commented Jul 23, 2019 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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