Ponder This Challenge - January 2026 - Number splitting
- Ponder This
Given an board and a starting location with and , Alice and Bob play the following game: Alice begins by placing a pawn on square , then Bob moves the pawn to an adjacent square of the four potential neighboring squares (diagonals don't count) and removes the square the pawn left from the board. Alice makes the next move, and they alternate until a player has no possible move and loses the game.
Since this is a game obeying Zermalo's theorem, given and either Alice can force a win, or Bob can force a win. Call an "A" square for the board if Alice can force a win, and "B" if Bob can force a win.
To complicate the game, we can remove some of the squares in the board before the game begins, in the following manner. Fix two prime numbers , and label each square in the board with a number, such that square is labelled (recall that indexing starts from 1, not 0). Now, pick a prime number , and remove from the board all the squares whose label is divisible by .
For example, it can be seen that for , the board is
A B A
B A B
A B A
But if we choose , as which is divisible by 5 the board becomes
B B B
B # B
B B B
With # denoting the missign square in the middle.
Given a board size , two primes and a set of prime numbers, for each we can count the number of "A" and "B" squares in the board (we don't count "#"). We can then sum those values over all the possible .
For example, for and and we have a total of "A" and "B".
Your goal: Find the total number of "A" and "B" for , and being the set of all prime numbers lower than 100.
A bonus "*" will be given for finding the total number of "A" and "B" for , and being the set of all prime numbers lower than 500.
The numerical solutions are:
Iterating over all cases is simple. The challange in the riddle is - given a specific board, how to find the "A" and "B" squares in it.
This is an example of the undirected vertex geometry game, which can be played in general on any finite undirected graph, and there is a relatively simple graph-theoretic criterion: A vertex is an "A" vertex (whoever starts on it can force a win) if there exists a maximum matching of the graph that does not contain that vertex.
Since the graph in question is bipartite, one can use the Hopcroft-Karp algorithm to find one maximum matching. Once such a matching is found, the Dulmage–Mendelsohn decomposition can be used to identify which vertices are part of every maximum matching of the graph.