Project Euler Lab - Problem 930

#930 - The Gathering

● ResearchOfficial difficulty: 100%RandomnessTier C - reduced scale in browser; full scale in notebookNot viewed
↖ Euler Lab

Given \(n\ge 2\) bowls arranged in a circle, \(m\ge 2\) balls are distributed amongst them.

Initially the balls are distributed randomly: for each ball, a bowl is chosen equiprobably and independently of the other balls. After this is done, we start the following process:

  1. Choose one of the \(m\) balls equiprobably at random.
  2. Choose a direction to move - either clockwise or anticlockwise - again equiprobably at random.
  3. Move the chosen ball to the neighbouring bowl in the chosen direction.
  4. Return to step 1.

This process stops when all the \(m\) balls are located in the same bowl. Note that this may be after zero steps, if the balls happen to have been initially distributed all in the same bowl.

Let \(F(n, m)\) be the expected number of times we move a ball before the process stops. For example, \(F(2, 2) = \frac{1}{2}\), \(F(3, 2) = \frac{4}{3}\), \(F(2, 3) = \frac{9}{4}\), and \(F(4, 5) = \frac{6875}{24}\).

Let \(G(N, M) = \sum_{n=2}^N \sum_{m=2}^M F(n, m)\). For example, \(G(3, 3) = \frac{137}{12}\) and \(G(4, 5) = \frac{6277}{12}\). You are also given that \(G(6, 6) \approx 1.681521567954e4\) in scientific format with 12 significant digits after the decimal point.

Find \(G(12, 12)\). Give your answer in scientific format with 12 significant digits after the decimal point.

This problem is taken from Project Euler, Problem 930.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=930. Published Sunday, 2nd February 2025, 10:00 am. Solved by 141 members at time of mirroring.

Learning mode

Pick how much scaffolding you want. Your choice is remembered per problem.

Scratchpad

Mathematical notes, formulas, pseudocode, hypotheses, complexity notes. Saved automatically with your progress.

Python workbench

Tier C - reduced scale in browser; full scale in notebook
Browser runs a reduced, clearly-labelled educational scale; the original scale is provided in a local notebook.

Real Python (Pyodide) in a sandboxed Web Worker - no network, no filesystem, no DOM access. Ctrl/Cmd+Enter runs. Escape leaves the editor. Stop terminates the worker.

Python runtime not loaded (it boots on first run - a one-time local load).

Check your answer

Answers are checked against a salted hash held in a separate file - not printed in this page. This prevents accidental spoilers; it is not cryptographic protection (see the build notes).

Progressive hints

Confidence

Low confidence schedules this problem for spaced review, even if you solved it.

Reference solution

Spoiler
The complete original explanation (interpretation, naive approach, insight, proof, complexity, Python implementation, tests, common mistakes, alternatives) is hidden and lazy-loaded. Reveal it only after a meaningful attempt - the struggle is where the learning happens.