### 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

21 November 2016

Posted by on **From New Scientist #2296, 23rd June 2001** [link]

George lives in a long road in which the houses are numbered from one with no numbers missing. He has calculated that the total of all the house numbers less than his is equal to the total of all the house numbers greater than his.

George’s brothers, Dave, Ernest and Fred, live in shorter roads than George, but they can each make the same claim regarding house numbers. The brothers’ four house numbers have different numbers of digits.

Hearing this story, George’s drinking friend scribbled on a beer mat for a while, then he asked: “George, does your road have nearly 10,000 houses?”

“No, not nearly that many,” George replied.

How many houses are there in total in the four roads? And what answer would the man in the pub have given to that question before being corrected?

[enigma1140]

Advertisements

%d bloggers like this:

This Python program calculates possible

(n, m)pairs wherenis the number of houses in the street, andmis the “triangular median” – i.e. the house number where the sum of all house numbers lower thanmis equal to the sum of all house numbers higher thanm. It runs in 63ms.Solution:The total number of houses in all four streets is 2026. The man in the pub would have given the answer 10145, before being corrected (assuming he had come up with a viable solution).The number of houses in the four streets are: 8, 49, 288, 1681. The final value is the number of houses in George’s street.

The corresponding “triangular medians” are: 6, 35, 204, 1189, so George lives in house 1189 of 1681.

The next largest number of houses in a street is 9800 (“nearly 10,000”), with a triangular median of 6930.

After that the next largest number of houses is 57121, with a triangular median of 40391.

If there are

nhouses in the street and the triangular median ismthen we have:Which simplifies to:

So we are interested in triangular numbers that are also square, see [ https://en.wikipedia.org/wiki/Square_triangular_number ], which can be generated as follows:

The sequence

N[]whereST[k] = T(N[k])(i.e.ST[k]is theN[k]th triangular number) can be generated as follows:The sequence

M[]whereST[k] = M[k]²(i.e.ST[k]is theM[k]th square number) can be generated as follows:The following Python program will generate as many

(n, m)pairs as you like (the number can be specified on the command line) such thatm² = T(n).The default is to generate the first 8 elements of the sequence, which is sufficient to solve this problem:

See also OEIS A001108, A001109, A001110.

A solution using my number theory library: