Project Euler Lab - Problem 661

#661 - A Long Chess Match

● ResearchOfficial difficulty: 82%Two-player gamesTier C - reduced scale in browser; full scale in notebookNot viewed
↖ Euler Lab

Two friends \(A\) and \(B\) are great fans of Chess. They both enjoy playing the game, but after each game the player who lost the game would like to continue (to get back at the other player) and the player who won would prefer to stop (to finish on a high).

So they come up with a plan. After every game, they would toss a (biased) coin with probability \(p\) of Heads (and hence probability \(1-p\) of Tails). If they get Tails, they will continue with the next game. Otherwise they end the match. Also, after every game the players make a note of who is leading in the match.

Let \(p_A\) denote the probability of \(A\) winning a game and \(p_B\) the probability of \(B\) winning a game. Accordingly \(1-p_A-p_B\) is the probability that a game ends in a draw. Let \(\mathbb{E}_A(p_A,p_B,p)\) denote the expected number of times \(A\) was leading in the match.
For example, \(\mathbb{E}_A(0.25,0.25,0.5)\approx 0.585786\) and \(\mathbb{E}_A(0.47,0.48,0.001)\approx 377.471736\), both rounded to six places after the decimal point.

Let \(\displaystyle H(n)=\sum_{k=3}^n \mathbb{E}_A\left(\frac 1 {\sqrt{k+3}},\frac 1 {\sqrt{k+3}}+\frac 1 {k^2},\frac 1 {k^3}\right)\)
For example \(H(3) \approx 6.8345\), rounded to 4 digits after the decimal point.

Find \(H(50)\), rounded to 4 digits after the decimal point.

This problem is taken from Project Euler, Problem 661.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=661. Published Saturday, 16th March 2019, 10:00 pm. Solved by 278 members at time of mirroring.

Why this is useful

Probability Statistics. Expectation and state-based probability reasoning underpin pricing, risk, and statistical inference (Phases 7, 11, 13).

We classify relevance honestly - not every Euler problem is a trading application.

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.