Open problems / 014

Moving stones between equal piles

Start with $n$ piles of one stone. A move takes two piles of the same size and shifts any number of stones from one to the other. Kagey asks how long a game can last. We do not know. We do know exactly which partitions of $n$ a game can reach, which answers the four questions about reachability and refutes a formula that fits the first hundred published terms.

The game

Start with $n$ piles of one stone each. A move picks two piles with the same number of stones and transfers any positive number of stones from one to the other. A state is the multiset of pile sizes, so a state is a partition of $n$, and empty piles are dropped.

On partitions the move reads: choose two parts equal to $a$ and an integer $1 \le j \le a$, and replace them by $a+j$ and $a-j$, deleting the second when $j = a$. A state is terminal when its parts are distinct, because then no two piles match and nothing can be played.

What is the greatest number of steps that can occur?

Write $g(n)$ for that number, which is A292729. Eight related questions come with it: the number of states A292726, whether the number $c(n)$ of partitions that cannot be reached is $1$ for every prime and $0$ exactly for powers of two, the least and greatest game lengths A292836 and A292729, the number of games, the number of terminal states A292728, and a variant in which stones may be redistributed among any set of piles of equal size.

The main question is open. The reachability questions are answered completely.

sum of squares of the pile sizes791113151719212527293749111111121111122111311112221321132241113314214351152617startno move produces it
Every game on $7$ stones. Rows are the sum of squares of the pile sizes, which every move raises, so the fourteen reachable states sit on a ladder and every move runs down it. States are written as their pile sizes, largest first. Four states are terminal and ten maximal games reach them, the shortest in four moves and the longest in eight. The run of eight is drawn heavier. The fifteenth partition of $7$ is $[7]$, at the foot of the ladder, and no move produces it.

Running the moves backwards

Reversing a move gives two operations on a partition:

  • (S) replace an even part $x$ by two parts $x/2$,
  • (A) replace two parts $x > y$ of the same parity by two parts $\tfrac{x+y}{2}$.

Let $\Sigma_2(\lambda)$ be the sum of the squares of the parts. A move with parameter $j$ raises $\Sigma_2$ by exactly $2j^2$, because $(a+j)^2 + (a-j)^2 - 2a^2 = 2j^2$. Since $\Sigma_2$ takes values between $n$ and $n^2$, every game is finite and so is every run of backward moves.

A partition of $n$ admits no backward move if and only if it is $[d^{n/d}]$ with $d$ odd.

If no backward move applies there is no even part, since (S) would take it, so every part is odd. Two distinct parts would then have the same parity and allow (A). So all parts are one odd number $d$. The converse is the same two observations read the other way.

A partition other than $[1^n]$ is reachable exactly when some backward move takes it to a reachable partition. So run backward moves from $\lambda$ until stuck. The run ends at some $[d^{n/d}]$ with $d$ odd, and if $d$ can be made $1$ then $\lambda$ is reachable. This is Neder's argument, and it already answers two of the questions.

$c(n) = 0$ if and only if $n$ is a power of two, and $c(n) = 1$ if and only if $n$ is an odd prime, in which case the one missing partition is $[n]$.

C. Neder proved this in a comment on A292726 in January 2019, so Kagey's questions 2 and 3 were settled before this note. For the prime $2$ the answer to question 2 is $c(2) = 0$ rather than $1$. Everything below is built on the argument, which is why it is stated here.

Which states are unreachable

Let $\mathcal{B}(n)$ be the set of partitions of $n$ whose parts share an odd prime factor. Backward moves preserve that property, since $r \mid x$ and $r \mid y$ give $r \mid \tfrac{x+y}{2}$ for odd $r$, and $r \mid x$ is equivalent to $r \mid x/2$. Induction on $\Sigma_2$ then puts all of $\mathcal{B}(n)$ out of reach.

That is not all of it. At $n = 6$ the partition $[5,1]$ has coprime parts, and its only backward move lands on $[3,3]$. Every exception is of this kind.

A partition $\lambda$ of $n$ cannot be reached from $[1^n]$ if and only if

  1. $\lambda \in \mathcal{B}(n)$, or
  2. $\lambda$ has $k \ge 2$ parts, they are distinct and odd, and for every two parts $x \ne y$ some odd prime divides $n$ and all $k-2$ parts other than $x$ and $y$.

For two parts, (ii) says $\lambda = [x,y]$ with $x \ne y$ odd and $n$ not a power of two. For three parts it says the parts are distinct and odd and each shares a factor with $n$.

Two different pairs cannot be served by the same prime unless $\lambda$ lies in $\mathcal{B}(n)$, so a partition of type (ii) outside $\mathcal{B}(n)$ with $k$ parts needs $\binom{k}{2}$ distinct odd primes dividing $n$. Three parts therefore need $n$ odd with three distinct prime factors, and four parts need $n \ge 2 \cdot 3 \cdot 5 \cdot 7 \cdot 11 \cdot 13 \cdot 17 = 510510$.

n = 65, 13, 3average3 divides bothn = 10595, 7, 395, 751, 51, 33 divides all95, 349, 49, 77 divides all7, 395, 5, 55 divides all
Why type (ii) exists. A state is unreachable when every backward move from it is unreachable. From $[5,1]$ the one backward move averages $5$ and $1$ and gives $[3,3]$, whose parts share the factor $3$. From $[95,7,3]$ there are three backward moves, one per pair of parts, and they give $[51,51,3]$, $[49,49,7]$ and $[95,5,5]$. A rule under a box marks a state whose parts share an odd prime factor, so that state is already known to be out of reach. The three primes used are $3$, $5$ and $7$, and $105 = 3 \cdot 5 \cdot 7$.

The smallest $n$ carrying a type (ii) partition with more than two parts is $105$, where there are six of them: $[95,7,3]$, $[77,25,3]$, $[93,7,5]$, $[91,9,5]$, $[51,49,5]$ and $[65,33,7]$. The next is $n = 165$, with eight. Four parts first occur at the smallest $n$ the prime count allows, and they do occur there: $[503503, 5967, 935, 105]$ is a partition of $510510$ in which each of $3, 5, 7, 11, 13, 17$ divides exactly two parts.

Counting them

Write $P$ for the partition function, $Q$ for partitions into distinct parts, $\mu$ for the Möbius function and $\varphi$ for Euler's function. The characterisation turns into closed formulas.

$c(n) = b(n) + e(n) + s(n)$, where

$$b(n) = -\!\!\sum_{\substack{d \mid n,\ d > 1\\ d \text{ odd}}}\!\! \mu(d)\, P(n/d),$$

$e(n) = \varphi(n)/2$ when $n$ is even and not a power of two and $e(n) = 0$ otherwise, and $s(n)$ counts the type (ii) partitions with at least three parts and no common odd prime. The number of reachable terminal states is $t(n) = Q(n) - b_Q(n) - e(n) - s(n)$, with $b_Q$ defined like $b$ with $Q$ in place of $P$.

So A292726 is $P(n) - c(n)$ and A292727 is $c(n)$, which answers question 1, and A292728 is $t(n)$, which answers question 7. The two conditional statements conjectured in A292728, that $t(n) = Q(n)$ exactly for powers of two and $t(n) = Q(n) - 1$ exactly for odd primes, follow.

Special cases come out directly: $c(2^k) = 0$, $c(p^k) = P(p^{k-1})$ and $c(2^k p) = P(2^k) + 2^{k-2}(p-1)$ for odd primes $p$. The last contains Neder's $c(2p) = (p+3)/2$ and proves his two conjectures $c(4p) = p+4$ and $c(8p) = 2p+20$.

The term $s(n)$ is zero for most $n$. It vanishes unless $n$ is odd with at least three distinct prime factors or $n \ge 510510$. Our first guess was $c(n) = b(n) + e(n)$, with no $s$ at all. That formula agrees with all $100$ published terms of A292727. It is false. The first failure is $n = 105$, where it gives $15827$ and the truth is $15833$, the difference being the six partitions listed above. A bottom-up enumeration of the unreachable set straight from the definition, using no theorem, returns $15833$.

The longest game

Every game can be continued until it is terminal, so $g(n)$ is the length of a longest game as well as the greatest number of steps. Question 5 asks for the same quantity as the main question.

For all $n \ge 1$,

$$\frac{n^{3/2}}{2\sqrt2} - \frac{n}{2} \le g(n) \le \frac{n^2}{4} - \frac{n}{2} + 1.$$

Both come from the same identity. A game of $L$ moves with parameters $j_1, \dots, j_L$ ending at a terminal state $\lambda$ satisfies

$$2\sum_{i=1}^{L} j_i^2 \;=\; \Sigma_2(\lambda) - n.$$

For the lower bound, play $j = 1$ every time. Such a game takes $(\Sigma_2(\lambda) - n)/2$ moves, its terminal state has $k$ distinct parts with $k^2 < k(k+1) \le 2n$, and Cauchy–Schwarz gives $\Sigma_2(\lambda) \ge n^2/k \ge n^{3/2}/\sqrt2$. For the upper bound, the move that creates the largest pile $s$ must have $j \ge s - n/2$ when $s > n/2$, and the other $L-1$ moves contribute at least $2$ each.

The integer part of the upper bound is attained for $n \le 5$ and never again up to $n = 80$. The identity also shows where the difficulty sits. A long game needs a terminal state with a large sum of squares, hence a large pile, while the moves that build a large pile quickly are the ones that use up the sum of squares $j^2$ times as fast.

Values of $g$ were known for $n \le 60$. Two independent longest-path computations, one forward from the terminal states and one backward from $[1^n]$, extend them to $n \le 80$.

$n$$+1$$+2$$+3$$+4$$+5$$+6$$+7$$+8$$+9$$+10$
$0$0113448101112
$10$16202224273135384345
$20$47525762677174798390
$30$95101106111114118126132138146
$40$152156161167172180189194204208
$50$216221228234242249258264274282
$60$291296305311319327336343351362
$70$371379387397404412420429439447
10203040506070800.00.51.01.52.0nvalue ÷ n^1.5terms 61 to 80 are newupper bound n²/4 − n/2 + 1g(n)j = 1 only (A121924)lower bound
The two bounds and the data, everything divided by $n^{3/2}$. On this scale the lower bound flattens at $1/(2\sqrt2) = 0.354$ and the upper bound climbs like $\sqrt{n}/4$, so the question of the true order of growth is whether the curve for $g$ stays bounded. Across the range drawn it rises, though not at every step and not at the last one. The ratio $g(n)/n^{3/2}$ is $0.48$, $0.56$, $0.61$ and $0.62$ at $n = 16, 32, 60, 80$. The lower curve is the game that only ever moves one stone, A121924, whose closed form due to S. Wagner grows like $0.47\,n^{3/2}$.

A least-squares fit of $\log g$ against $\log n$ over $30 \le n \le 60$ gives $g(n) \approx 0.338\, n^{1.64}$. The fit was recorded before the new terms were computed and it predicts all twenty of them to within $1.2\%$. That is not evidence that $1.64$ is the exponent. The data cannot distinguish a power above $3/2$ from $n^{3/2}$ times a slowly growing factor, and from $n = 76$ on the fit sits above every value.

The longest games inspected, all of them with $n \le 40$, look alike. About nine moves in ten use $j = 1$, for instance $90$ of $101$ at $n = 32$ and $132$ of $146$ at $n = 40$, and the rest are small except for one or two large jumps. At $n = 32$ and $n = 40$ every terminal state that ends a longest game has a largest part above $n/2$ and at most three parts besides it: six such states at $n = 32$, among them $[20,8,3,1]$ and $[24,8]$, and five at $n = 40$, among them $[28,8,3,1]$ and $[27,7,5,1]$. At $n = 8$ and $n = 16$ the single pile $[n]$ ends a longest game.

What was checked

A verification script in the repository runs in about thirty seconds and tests the statements above against computations that do not use any of the theorems.

  • For every $n \le 40$, a forward breadth-first search from $[1^n]$ and a separate backward-move recursion over all $215{,}307$ partitions agree on which states are reachable. The characterisation is tested on the same partitions.
  • A bottom-up enumeration of the unreachable set, generated from the definition alone, matches $b(n) + e(n) + s(n)$ for $41 \le n \le 120$, $n = 135$ and $n = 165$, including the six partitions at $105$ and the eight at $165$.
  • The formulas match every published term: A292726 and A292728 to $n = 60$, A292727 to $n = 100$.
  • $g$, $\ell$ and the terminal counts are each computed twice, once forward from the terminal states and once backward from $[1^n]$, for $n \le 40$ and again for $61 \le n \le 80$. The two runs agree with each other and with the published terms wherever those exist. For $41 \le n \le 60$ the table above reproduces the published terms rather than recomputing them. The terms $61 \le n \le 80$ of $g$ are new.
  • The repository's ledger records predictions written down before the runs that tested them. The twenty terminal counts for $61 \le n \le 80$ all came out exactly as predicted, as did the six unreachable partitions of $105$ that refute $b + e$. The fit for $g$ was recorded the same way and landed within $1.2\%$ of the twenty new values, matching six of them exactly.

What is open

The main question. We can prove neither $g(n) = O(n^{3/2})$ nor, failing that, $g(n) = o(n^2)$. The upper bound charges only the single move that creates the largest pile. A better bound would have to charge the moves that made the two piles it came from, and so on.

There is no description of the longest games, or of the terminal states that end them, beyond the pattern in the values computed so far.

Questions 4 and 6, the least number of steps $\ell(n)$ and the number of games, are only computed here, not explained. For the first, $\ell(n) \ge n - \lfloor(\sqrt{8n+1}-1)/2\rfloor$ because a move removes at most one pile and a terminal state has at most that many piles, but the true values are larger, with $\ell(100) = 92$ against a bound of $87$. The number of games starts $1$, $1$, $1$, $2$, $2$, $4$, $10$, $60$, $93$, $414$, $1842$, $24044$, $140405$, $1304266$ and has no formula here.

Question 8 has a one-line answer as far as reachability goes. If stones may be redistributed among any set of piles of equal size, then every partition of $n$ is reached in a single step, because all $n$ piles are equal at the start. So $c$ vanishes identically for that variant, and only the questions about game lengths remain. Those are not treated here.