# The Weight Problem of Bachet de Méziriac

A merchant had a forty-pound measuring weight that broke into four pieces as the result of a fall. When the pieces were subsequently weighed, it was found that the weight of each piece was a whole number of pounds and that the four pieces could be used to weigh every integral weight between 1 and 40 pounds.

What were the weights of the pieces?

Spoilers ahead! You might want to try it yourself.

### Background

This problem stems from the French mathematician Claude Gaspard Bachet de Meziriac (1581-1638), who solved it in his famous book Problemes plaisants et dilectables qui se font par les nombres, published in 1624.

Bachet was the earliest writer who discussed the solution of indeterminate equations by means of continued fractions. He also did work in number theory and found a method of constructing magic squares. Some credible sources also name him the founder of the Bézout’s identity.

Source : Wikipedia

We can distinguish the two scales of the balance as the weight scale and the load scale. On the former we will place only pieces of the measuring weight; whereas on the latter we will place the load and any additional measuring weights. It is necessary to place measuring weights on the load scale. For example, in order to weigh one pound with a two-pound and a three-pound piece, we place the two-pound piece on the load scale and the three-pound piece on the weight scale.

For the sake of explanation, we introduce the term preponderance. If two pieces weighing 5 and 10 pounds each are on one scale, and three pieces weighing 1, 3, and 4 pounds each are on the other, we say that these pieces give the first scale a preponderance of 7 pounds.

### An Intermediate Problem

Suppose that we have a series of measuring weights which enable us to weigh all the integral weights from 1 through N, then if we were to chose another measuring weight P such that the range of possible weight measurement is maximized, what should be the weight of P?

Let the weight of P be X > N. For the arrangement to measure weight K, if we place P on the weight scale, this will give the weight scale a preponderance of X+K; if we place P on the load scale, this will give the load scale a preponderance of X-K, which leads to swapping roles between the two scales.

In summary, by adding P we can measure weight [X-N,X+N]. Since we are able to measure weights [1,N] already, to maximize the range we shall greedily merge both ranges, in result having [1,X+N]. To achieve this, the lower bound of [X-N,X+N] should be followed by the higher bound of [1,N], thus the equation:

$X-N=N+1 \rightarrow X=2N+1$

### Solution

We will approach this problem using casework (aka brute-force). Starting with 1, we will get the following table :

Piece Weight Range
1 1 1
2 3 4
3 9 13
4 27 40

Their sum is indeed 40, indicates that this is our desired answer.