### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,367)
- misc (4)
- project euler (2)
- puzzle (90)
- puzzle# (48)
- site news (58)
- tantalizer (94)
- teaser (7)

### Site Stats

- 233,129 hits

Programming Enigma Puzzles

7 October 2013

Posted by on **From New Scientist #2546, 8th April 2006**

It was Penny’s birthday and Joe provided a box of 25 sweets. He arranged five saucers in a circle and placed 5, 1, 9, 2 and 8 sweets in that order round the circle in the saucers.

To share out the sweets Penny and her four friends had to take turns to remove sweets from or replace sweets in a saucer of their choice until there were five sweets in each. Any sweets removed were placed temporarily on the table.

However, Joe stipulated that if they moved a number of sweets into or out of a saucer, then they must move the same number of sweets into or out of the two adjacent saucers. So each turn consisted of three moves. Needless to say they tried to share out the sweets as quickly as possible.

What is the minimum number of turns needed to share out the sweets?

Penny and Joe are revisited in **Enigma 1410**.

[enigma1386]

%d bloggers like this:

I generalised the code I wrote to determine the minimum sequence of moves for

Enigma 1410, so that the initial sequence can be specified. Although it doesn’t need the initial analysis, this is a harder puzzle and it took 72s to find 26 ways of solving the puzzle in 8 moves. (Although it finds the first of these minimal solutions after about 16s. I recoded from Python 3 to Python 2 so that I could use PyPy to speed up the execution).This code is less time efficient than a breadth first search, as it considers increasing numbers of maximum moves, so will become hopelessly bogged down if a large number of moves is required. But it won’t use much memory while it’s working.

Solution:The minimum number of turns required is 8.