Ok, I need to make a nim game and try to find a strategy to always win with the next nim game:
21 matches, players 1 and 2 took 1, 2, 3, 4 or 5 matches in each turn, and one cannot match the match of the previous player. The winner receives a win if / when they take the last match.
I need to program something, but I don’t even understand what needs to be started. How can I find a winning strategy with this type of game?
EDIT:
So, I decided that you will always win when you get to 7 matches, which are still in the middle. Another can take 2-5, and you can add up to 7 by taking the last one. when the other accepts 1, you accept 3 (the other cannot accept 3, and then) and must choose 1 or 2, in which case you will receive the second and win.
However, the transition from 21 to 7 is a mystery to me, I cannot understand how you can always be a person who has reached 7.
EDIT 2: OK, so without the rule that you cannot take the same as the previous player, it's pretty simple, I think.
You must make k = 5 + 1 = 6. then you must make the first move so that the matches remain then% 6 = 0. Thus, in this case, first take 3, and then fill up the replenishment of another player to 6. However, in in this case, it will not work, because the other player can take 3, after which you cannot take 3 to fill up to 6. So there is my problem. Any ideas?
EDIT3:
ok, so you say that I can force 7 matches. However, suppose that I accept the same thinking until stage 14-7 matches. (then this is another twist)
There are two scenarios: 1: it takes 2-5, and I fill it up to seven, which allow 7 there, and I win. 2: it takes 1, so it remains 13. When I take 3, as I do in (7-0), it becomes 10. Then it takes 5, and I can no longer take 5 to finish, and I will lose.
Here lies the problem when scenario 2 is not a problem in the (7-0) -stage now. How to solve this?
YES, SOLUTION:
btw, na speler 1 means: after the player 1 turn, etc. (I am Dutch).

Ok, so I tried some things, and I think I have a solution. First you must accept 1 match as the first player. Then other guys can take 2-5 matches. You compare (pun intended) your amount to 7, so you will always have (21-1-7 =) 13 matches in the middle left. Then player 2 turns again, and there are two scenarios: player 2 accepts 1,2,4, or 5 matches, in which case you take so many matches that the left side will be 7. (as mentioned earlier, when you accept matches so there’s 7 left, you will always win). The second scenario is that player 2 takes 3 matches, in which case there are 10 in the middle when it is your turn. You cannot take 3 to make 7, because you cannot take 2 times the same amount. So, you take 5, so there is 5. Player 2 then cannot take 5 to win and must choose 1-4, after which you can take the rest and win.
This is a solution, I think. I somehow came across this because I noticed this:
Normal Nim game with module, etc .:
P2 1 2 3 4 5 P1 5 4 3 2 1 ------------------ 6 6 6 6 6
But you cannot do 3.3 here, so this is liek this:
p2 1 2 3 4 5 p1 5 4 3 2 1 --------------------- 7 7 7 7
So you can do 7 every time, and 1 is a special case. I don’t know why, but I intuitively took 1 as a starting point, as it seems that you need to take the initiative in order to be able to control other moves. (you cannot do it twice 1, so the other should take 2-5, which allows you to control)
In any case, THANKS a lot for all the help. Also for the entire written program. I could not use it because it did not compile as a lack of good java skills :), and I also wanted to solve it myself.
Anyway, I saw that it was a wiki, luck for people in the future, trying to solve it!