### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,158)
- misc (2)
- project euler (2)
- puzzle (40)
- site news (44)
- tantalizer (42)
- teaser (3)

### Site Stats

- 177,972 hits

Advertisements

Programming Enigma Puzzles

11 January 2012

Posted by on **From New Scientist #2762, 29th May 2010** [link]

An encyclopaedia salesman was working his way along a row of terraced houses. His standard patter was to ask about the children in the household. At one house the lady who answered the door told him: “I have three children. The product of their ages is 72. The sum of their ages equals the number of an adjoining house next door.” It was impossible for the salesman to work out the ages from this.

At the next house the lady who answered the door told him “I have three children. The product of their ages is 72. The sum of their ages equals the number of an adjoining house next door.” It was impossible for the salesman to work out the ages from this either. At the next house exactly the same thing happened again, and it was impossible for the salesman to work out the ages.

At a house a little further along the terrace exactly the same thing happened again and it was impossible for the salesman to work out the ages. At the next house exactly the same thing happened again, but this time the salesman was able to work out their ages.

What were they?

[enigma1597]

Advertisements

%d bloggers like this:

It’s a bit tricky to work out what is required here. Does the salesmen go along the street by increasing number, or decreasing number? Are the houses numbered consecutively, or does each differ from its neighbours by 2? Can “a little further along the terrace” mean next door, or not?

You can make a more complicated version of the program below and discover that the houses need to be numbered consecutively, and the salesman must visit them in increasing order. If you interpret “a little further along the terrace” to include next door, then you get an additional way of solving the puzzle, but it doesn’t affect the answer.

Given those constraints this Python program runs in 33ms.

Solution:The children’s ages are 1, 8 and 9.And here’s the modified version which checks for the houses going in increments of 1 or 2 and also for the salesmen visiting the houses in increasing or decreasing order.

The runtime is also 33s.