Brain-Teaser 409: House number
From The Sunday Times, 9th March 1969 [link]
I live in a long street in which the houses are all on one side numbered consecutively.
If I add my house number to the sum of a certain number of consecutive house numbers on my immediate left, the answer is equal to the sum of the same number of consecutive house numbers on my immediate right.
Moreover, if I add the square of my house number to the sum of the squares of a different number of consecutive house numbers on my immediate left, the result is equal to the sum of the squares of the same number of consecutive house numbers on my immediate right.
I do not live at number 12, and perhaps I should add that my house number is less than 14,000.
What is it?
This puzzle is included in the book Sunday Times Brain Teasers (1974).
[teaser409]




Jim Randell 11:13 am on 18 December 2022 Permalink |
Here is a constructive solution.
For each possible house number value n, it look for left/right sequences that give equal sums (the left sequence includes n and the right sequence does not).
It runs in 223ms.
Run: [ @replit ]
from enigma import (irange, identity, sq, printf) # find the size of left/right sequences with equal sums # return the size of the right sequence (left is 1 more) def check(n, fn=identity): (sl, sr, a, b) = (fn(n), 0, n, n) while sl > sr and a > 1: a -= 1 b += 1 sl += fn(a) sr += fn(b) if sl == sr: return (b - n) # consider values for n for n in irange(1, 13999): # check for sum k1 = check(n) if not k1: continue # check for sum of squares k2 = check(n, sq) if not k2: continue # output solution printf("n={n}: k1={k1} k2={k2}")Solution: The house number is: 420.
And we have:
With some analysis we can have a faster program.
If we consider the setter at house n, and the k consecutive houses immediately before and after him we have:
There are (k + 1) terms of the left and k terms on the right, so matching them up pairwise, except the n term on the left, we get:
So the house number n is the product of 2 consecutive integers.
We have a similar situation with the squares of the numbers:
Which we can pair up like this:
So the house number n is also twice the product of 2 consecutive integers.
The following Python program finds the required answer using this analysis, and also verifies that the sums of the sequences are equal.
It runs in 59ms. (Internal runtime is 317µs).
Run: [ @replit ]
from enigma import (irange, inf, sumsq, printf) # verify left/right sequences def verify(ls, rs, fn): # construct the sequences (ls, rs) = (list(ls), list(rs)) # and their sums (sl, sr) = (fn(ls), fn(rs)) # output results printf("-> [{l0}..{l1}] = {sl}; [{r0}..{r1}] = {sr}", l0=ls[0], l1=ls[-1], r0=rs[0], r1=rs[-1]) if sl != sr: printf("=> FAIL") # collect values: k -> k * (k + 1) d = dict() for k in irange(1, inf): n = k * (k + 1) if not (n < 14000): break # have we seen half this value? m = d.get(n // 2) if m is not None: printf("n={n}: k={k} m={m}") # output solution verify(irange(n - k, n), irange(n + 1, n + k), sum) verify(irange(n - m, n), irange(n + 1, n + m), sumsq) # record this value d[n] = kAnd we find the same two candidate solutions:
The next two candidates would be:
Which is OEIS A098602 [ @oeis.org ].
And can be generated using the following recurrence relation:
LikeLike
John Crabtree 3:26 am on 21 December 2022 Permalink |
k and m are related by a negative form of the Pell equation, ie
(2k+1)² – 2(2m+1)² = -1
with values of (2k+1, 2m+1) = (1, 1), (7, 5), (41, 29), (239, 169), (1393, 985) etc
LikeLike
Jim Randell 3:57 pm on 1 October 2025 Permalink |
The house number n is the product of 2 consecutive integers, and also twice the product of a different 2 consecutive integers:
setting: X = 2x + 1, Y = 2y + 1, we get:
(Which is the Pell equation noted by John Crabtree).
We can then use the [[
diop_quad()]] solver from the pells.py library to solve this:from enigma import (div, printf) import pells # solve X^2 - 2.Y^2 = -1 for (X, Y) in pells.diop_quad(1, -2, -1): # X = 2x + 1, Y = 2y + 1 (x, y) = (div(X - 1, 2), div(Y - 1, 2)) if x is None or y is None: continue # calculate the house number (= x(x + 1) = 2y(y + 1)) n = x * (x + 1) if n < 1 or n == 12: continue if not (n < 14000): break # output solution printf("n={n} [X={X} Y={Y}; x={x} y={y}]")Solutions to the Pell equation are generated by the following recurrence relation:
LikeLike