**From New Scientist #886, 21st February 1974** [link]

Teddy and his brothers have set their hearts on a paint-box, a fire-engine, and a space-gun. So, when they received 20p each for digging the garden recently, each earmarked a different whole number of pennies for each toy. (I mean that each divided his 20p differently, not that no two boys allocated the same number [of pennies] to one toy).

Each, alas, fell far short of the sum needed. But then they had the happy idea of pooling resources. Each had devoted his largest sum to the space-gun which came to 52p in total, and, hooray, the gun cost 52p … Each had earmarked his smallest sum for the paint-box and that total too exactly bought it. Similarly they also had exactly enough for the fire-engine.

If I just add that Teddy’s 3p was the smallest contribution to anything, can you work out the price of the fire-engine?

[tantalizer335]

### Like this:

Like Loading...

Each brother divides (the entirety of) their 20p into 3 increasing amounts, which are to go towards (in ascending order), the paint box, the fire engine, and the space gun. We can use the [[

`decompose()`

]] function from theenigma.pylibrary to do this.We then select a decomposition containing 3p for Teddy, and some decompositions with all values greater than 3p for the brothers, and when we find a total contribution of 52p for the space gun we have found the solution.

In the following Python 3.10 code I decided to use

structural pattern matching(newly introduced in Python 3.10) to identify the solution condition. It is a powerful construct (and this use of it is only the tip of the iceberg), but it does mean the code will only run in Python 3.10 (or later), and may be confusing to people who have not encountered it before.Run:[ @replit ] (a Python <3.10 version)Solution:The price of the fire engine is 28p.Teddy’s split is: (3, 4, 13)

And the splits for his 4 brothers are: (4, 5, 11), (4, 6, 10), (4, 7, 9), (5, 6, 9).

Giving the totals: paint box = 20p; fire engine = 28p; space gun = 52p.