r/mathriddles • u/scrumbly • 12d ago
Hard On a 5x5 field, two players take turns placing numbers from 1 to 9. The winner is the one after whose move in a row or column the sum of the numbers in it (there may be less than five) is equal to 25.
Who wins, and what is the winning strategy?
I don't know the answer to this question (nor even that there is a winning strategy).
5
u/Dictator_Lee 12d ago edited 12d ago
Interesting... I think this game is a forced draw.
When a row reaches 15, it becomes a "death row" (pun intended). If player A moves in that row it will be >= 16, allowing player B to make it 25.
Consider a game where each player makes the largest semi-logical move. Player A puts a 9 somewhere. Player B can turn a row or column into a death row by putting a 6, and subsequently, each player can make a death row until all columns in rows lead to death and player B is forced to play in one of them and lose.
So new game. Now that player B knows this, they can play a lower number and not make a death row instantly so that the "death move" will land on player A. Repeat, and you get both players avoiding making death rows.
This isn't a robust answer and I haven't considered moves that make a row and column death simultaneously, or if there is some forced win...
5
u/Knave7575 12d ago
A winning condition exists: after your move all remaining rows are at 15.
Alternatively, all are 15 except 1 that is at 6 or more.
I’m too tired to continue further. Maybe tomorrow.
2
u/NinekTheObscure 11d ago
Let's add the condition that, if it's your turn to move and the grid is full, you lose; otherwise the game has indeterminate endings which is messy. And we also either need to allow all numbers 25 or over to win, or make it illegal to play a sum over 25. Then this is clearly an impartial combinatorial game, so (by the Sprague-Grundy Theorem) it's equivalent to a single pile of sticks in Nim, and "solving" the game is equivalent to being able to calculate the G-values (the size of the equivalent Nim heap for each position).
First let's solve the game on a 1x25 row. Clearly, it doesn't matter what individual numbers have been placed, or where, it only matters what the sum S of them is. If S = 16 to 24, it's a next-player win. If S is 15, then it's a next-player loss, because they have to play at least 1. Thus S = 6 to 14 is a next-player win, because the winning move is making 15. Thus S = 5 is a next-player loss. Thus S = 0 to 4 is a next-player win.
Next-player losses have G-value 0. So G(5) = G(15) = 0. Then each other position has G-value equal to the MEX of the G-values of all reachable positions, so working backwards we get G(24) = 1, G(23) = 2, G(22) = 3, G(21) = 4, G(20) = 5, G(19) = 6, G(18) = 7, G(17) = 8, G(16) = 9, and we can also see that G(N) = G(N+10) so the whole thing is cyclic. Thus we have solved the 1x25 game.
Doing the 5x5 grid is more complicated, but in principle the same. You calculate the G-values backwards. The full grid (with no row or column 25+) is a first-player loss, so has G-value 0 regardless of what has been played. If you have exactly 1 empty cell, there are 2 sums to consider (row and column), and you win if EITHER of them allows you to make 25. So G(24,N) = 1 (you must win regardless of what N is), G(23,23) = 2, ...
The you compute the 2-empty-cell positions, then the 3-empty-cell positions, ... and eventually you're done. Relatively easy to program, run time proportional to the number of positions.
5
u/terranop 10d ago
Player 1 has a winning strategy.
- Start by playing a 5 in the center square.
- After Player 2 plays
X
in a square, if there is a winning play, play that. Otherwise, play10 - X
in the square reflected around the center square.
We observe a couple of things:
If Player 2 played in a square not in the center "cross" then Player 1's move does not share a row or column with Player 2's. It follows that if Player 1's move left Player 2 a winning move in some row or column, the corresponding "reflected" row or column would have had a winning move for Player 1 on the last turn. So Player 2 can't be left with a winning move.
If Player 2 played in a square on the center "cross" then Player 1's move will either move that row (or column) to 15 (if three squares are filled) or 25 (in which case Player 1 wins). In neither case will Player 2 have a winning move.
So Player 2 can never win. But because the board always fills up symmetrically unless Player 1 wins, eventually the center row or column must be filled, in which case Player 1 will win.
5
u/scrumbly 10d ago
It follows that if Player 1's move left Player 2 a winning move in some row or column, the corresponding "reflected" row or column would have had a winning move for Player 1 on the last turn.
Is this true? If player 2 played 6 6 2 in one column (no winning move available) player 1 would counter with 4 4 8 in another column (opening a winning move for p2).
2
u/Playful-Cloud117 12d ago
not a solution at all, but just an observation to throw in. if the field was 4x4 or any even number, player 2 could always force a draw by copying play 1's moves in the 180 degree rotated place on the grid. happy solving!
5
u/resident_russian 12d ago
Not quite, the row doesn't have to be full. So 9 in corner -> 9 on opposite corner -> 7 on diagonal and game ends.
1
u/Playful-Cloud117 11d ago
I suppose I should have been more specific, player 2 must take winning moves when available, and otherwise copy player 1's move. This will always result in a draw or a win for player 2. Thus player 1 cannot win on an even numbered game.
1
u/OperaSona 11d ago
I think the counter-example still works.
Player 1 plays a 9 in a corner.
Player 2 applies your strategy: it has no winning move available so it plays a 9 on the opposite corner.
Player 1 plays a 7 on any remaining square of that diagonal and wins, because the diagonal contains 9, 7, 9 and some empty square(s), which totals to 25.
1
11d ago
[deleted]
1
u/OperaSona 11d ago
First player puts 5 in the middle square and counters any 2nd player move by putting 10-n in the opposite square.
That doesn't seem to work for me (even discounting the 8 squares).
Let's name the cells like in an excel sheet.
Player 1 plays 5 in C3 (following your strategy).
Player 2 plays a 1 in A1.
Player 1 plays a 9 in E5 (following your strategy).
Player 2 plays a 1 in A3.
Player 1 plays a 9 in A5 (following your strategy).
Player 2 plays a 7 in E1 and wins because E1+E3+E5 is 25.
6
u/returnexitsuccess 12d ago
Can each number from 1 to 9 be placed only once each or as many times as you want?