### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,115)
- misc (2)
- project euler (2)
- puzzle (29)
- site news (43)
- tantalizer (29)
- teaser (3)

### Site Stats

- 166,357 hits

Programming Enigma Puzzles

11 July 2016

Posted by on **From New Scientist #2315, 3rd November 2001** [link]

I bought a few yards of expensive material recently and I suspected that I had been short-measured. So I took it to the local trading standards officer who measured it exactly in inches. She did not tell me the exact length but she did tell me that it involved two decimal places.

She then told me what the length was to the nearest inch (where exact halves are rounded up) and this did equal the whole number of yards which I had purchased.

Also, as required by a European directive, she changed her exact measurement in inches to centimetres (1 inch = 2.54 centimetres) and she told me the length of the material to the nearest centimetre.

From the things which she told me I was in fact able to work out the exact length of the material in inches and to see that I had actually been sold slightly more material than I had asked for.

How many yards of material had I asked for?

[enigma1159]

Advertisements

%d bloggers like this:

This Python code looks for the smallest number of yards that satisfies the given conditions. It runs in 124ms.

Solution:I originally asked for 12 yards of material.12 yards is the smallest number that satisfies the conditions of the puzzle text, but so does 12 + 25

kyards, for integer values ofk≥ 0.So the next smallest solution would be at 37 yards, which perhaps is a but much to count as “a few yards of material” (although I think 12 yards is leaving the realms of “a few” and entering “several yards of material” territory).

I think the following notes show how critical the wording is in this Enigma,

in respect of the statements “nearest inch” and “nearest cm”

In order to understand better the answer to this Enigma, I explored Jim’s

dictionary ‘r’ in more detail.

Dictionary ‘r’ has keys as a tuple in the format (inches,cm) plus values in

inches, expressed as a fraction.

We can get the dictionary print-out and the number of values for each key

by inserting a few lines of code, just before Jim’s exit() statement ie:

If we print out the (key,value) pairs in the dictionary ‘r’, we get:

key (432, 1097) – 35 values

key (432, 1099) – 1 value ie Fraction(43249, 100)

key (432, 1096) – 18 values

key (432, 1098) – 36 values

Fraction(43249, 100) is 432.49 inches and is a unique value in the dictionary

providing the solution to this Enigma.

Also, 432.49 inches is 432.49 * 2.54 = 1098.5246 cm, which is rounded up to

1099 cm, the nearest whole number of centimetres. 432.49 inches is also rounded

down to 432 inches to the nearest whole number of inches, which is

exactly 12 yards.