# Math game problem, not able to understand why the solution works?

Players A and B

Rules of the game:

• The game is played with two piles of matches. Initially, the first pile contains N matches and the second one contains M matches.

• The players alternate turns; A plays first.

• On each turn, the current player must choose one pile and remove a
positive number of matches (not exceeding the current number of
matches on that pile) from it.

• It is only allowed to remove X matches from a pile if the number of
matches in the other pile divides X.

• The player that takes the last match from any pile wins.

The solution i have thought for this problem is:

if n % m == 0 or m % n== 0 then player A will win
else we will find the reminder and quotient and count the moves

if quotient is > 1: and move is Odd then player A wins

2: move is even then player B wins

else swap the larger pile and smaller pile and repeater the above steps


## migrated from mathematica.stackexchange.comMay 19 at 10:10

This question came from our site for users of Wolfram Mathematica.

• This doesn’t look like it pertains to Mathematica the software from Wolfram Research. Did you post on the wrong site? – b3m2a1 May 19 at 10:05
• I am confused by the way you have used the word "divides". Suppose I am taking a number $n$ of matches from pile $B$, do you mean I can only do this if $n=ra$ where $r$ is an integer and $a$ is the number of matches in pile $a$ (so if $n$ is a multiple of $a$, which is what you have written). Or do you mean to say that you must have $a=rn$ with $n$ a factor of $a$? And are you allowing $r=0$? – Mark Bennet May 19 at 10:16
• @MarkBennet why are you confused about divides versus is divisible by ? – Roddy MacPhee May 19 at 12:33
• Who ever will got to zero first will win the game for example. I have 1 1 then A will win if I have 155 47 then A will win if I have 6 4 then B will win. – Raman Mishra May 19 at 12:34
• @RoddyMacPhee Well as phrased you only seem to be able to take matches from the larger pile (or both if they are equal), yet this is not mentioned as a feature. – Mark Bennet May 19 at 12:39