Project Euler Lab - Problem 566

#566 - Cake Icing Puzzle

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

Adam plays the following game with his birthday cake.

He cuts a piece forming a circular sector of \(60\) degrees and flips the piece upside down, with the icing on the bottom.
He then rotates the cake by \(60\) degrees counterclockwise, cuts an adjacent \(60\) degree piece and flips it upside down.
He keeps repeating this, until after a total of twelve steps, all the icing is back on top.

Amazingly, this works for any piece size, even if the cutting angle is an irrational number: all the icing will be back on top after a finite number of steps.

Now, Adam tries something different: he alternates cutting pieces of size \(x=\frac{360}{9}\) degrees, \(y=\frac{360}{10}\) degrees and \(z=\frac{360 }{\sqrt{11}}\) degrees. The first piece he cuts has size \(x\) and he flips it. The second has size \(y\) and he flips it. The third has size \(z\) and he flips it. He repeats this with pieces of size \(x\), \(y\) and \(z\) in that order until all the icing is back on top, and discovers he needs \(60\) flips altogether.

0566-cakeicingpuzzle.gif

Let \(F(a, b, c)\) be the minimum number of piece flips needed to get all the icing back on top for pieces of size \(x=\frac{360}{a}\) degrees, \(y=\frac{360}{b}\) degrees and \(z=\frac{360}{\sqrt{c}}\) degrees.
Let \(G(n) = \sum_{9 \le a \lt b \lt c \le n} F(a,b,c)\), for integers \(a\), \(b\) and \(c\).

You are given that \(F(9, 10, 11) = 60\), \(F(10, 14, 16) = 506\), \(F(15, 16, 17) = 785232\).
You are also given \(G(11) = 60\), \(G(14) = 58020\) and \(G(17) = 1269260\).

Find \(G(53)\).

This problem is taken from Project Euler, Problem 566.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=566. Published Saturday, 25th June 2016, 01:00 pm. Solved by 239 members at time of mirroring.

Why this is useful

Algorithmic Development. Graph/state-space search transfers to routing, dependency resolution, and execution-path optimisation (Phases 16, 17).

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

Prerequisites

Lessons that prepare you:
19.14 Computational Complexity, Feasibility Estimation, and Proving Algorithms Correct · 19.7 Dynamic Programming: Memoization and Tabulation · 19.9 Graph Algorithms: BFS, DFS, Dijkstra, and Minimum Spanning Trees

Recommended stepping-stone problems: #331 · #391 · #953

Concepts: game-theory graph-theory brute-force-reduction

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.