### 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,126 hits

Programming Enigma Puzzles

6 June 2018

Posted by on **From New Scientist #1002, 27th May 1976** [link]

A minor problem which has long troubled medical historians is why two seemingly identical Edwardian TB sanataria in Mercia should have strikingly different death rates. The answer turns out to be simple enough — St. Bede’s in fact had 3,185 more patients than St. Crispin’s.

How did this come to be overlooked? Well, the probable reason is that both were built on the same formula. Each had as many wings as it had wards in each wing and had as many wards in each wing as it had patients in each ward. This was so plainly the whim of some mad bureaucrat that no historian troubled to check whether the number of patients per ward was the same in each place.

So what is the figure in each case?

[tantalizer451]

%d bloggers like this:

If the characteristic numbers of St. Bede’s and St. Crispin’s are

bandcrespectively, then we are looking to solve:This Python program looks at increasing values of

cand the corresponding value of³√(c³ + 3185).It runs in 68ms.

Run:[ @repl.it ]Solution:C has 1728 patients (= 12³), B has 4913 patients (= 17³).Most of the reported run time is taken up in housekeeping of the Python interpreter. But we can use the

`Timer()`

class from theenigma.pylibrary to find the actual elapsed time of a chunk of code, and doing that we find the internal run time of this program is about 107µs. I came with a couple of other approaches, but they both clocked in with a similar, but slightly slower, internal run time of around 120µs.This puzzle strikes me as more trivial than most.

b must be at least 15 because 14³ < 3185 and cannot be more than 33 because 34³ – 33³ > 3185.

Even I could write a very short program in Basic, that would find the solution very quickly (without the need to take cube roots).

Though I have to say that run time is quite unimportant for something like this that is executed only once and is not a real-time control application. The time it takes to type in the program is inevitably very much greater!

Minor problem… so I agree, rather more trivial than most.

Thank you for fixing the > and <, Jim.

It’s since occurred to me that b³ – c³ = (b – c)(b² + bc + c²); and 3185 has prime factors 5, 7, and 13, so (b – c) must be one of those, which reduces the possibilities. If we tentatively take 31 as the upper limit for b, we can use single-length integer arithmetic, insert an inner loop for c, and avoid taking cube roots.

Using Hugh’s factorisation of b^3-c^3:

Here’s a solution that uses factorisation to solve the problem for a general difference in cubes:

So:

We can consider divisor pairs

pandqofNsuch thatp×q = N, andp < q.Then:

so:

so, if

(q – p²)is positive and divisible by 3 we can determine candidate values forbandcdirectly by looking at the divisor pairs of(q – p²) / 3.In fact if we have an integer

d:Then we have equations:

Solving for

cgives the following quadratic:Which, using the quadratic formula has a solution at:

and substituting for

d:Which gives a similar approach to Arthur’s method above – factorising

Nand then solving a quadratic equation.