Teaser 2198: Developing houses
From The Sunday Times, 31st October 2004 [link]
My Uncle Silas is a property developer. He recently bought some properties along a street of fewer than 400 houses. The odd-numbered houses were on the left side of the street, and the even-numbered houses were on the right. He bought eight adjacent houses on the left side of the street and seven adjacent houses on the right side. The sum of the house numbers on the left was a perfect square and was the same as the sum of the house numbers on the right.
What was the largest house number that he bought?
1000 Teasers and nearly 20 years ago.
[teaser2198]



Jim Randell 8:40 am on 9 January 2024 Permalink |
I assumed that the houses are numbered consecutively, starting with 1.
This Python program runs in 57ms. (Internal runtime is 421µs).
Run: [ @replit ]
from enigma import (irange, tuples, is_square, intersect, printf) # find <k> numbers from <seq> that sum to a perfect square def numbers(k, seq): # collect sequences by sum d = dict() for ns in tuples(seq, k): s = sum(ns) if is_square(s): d[s] = ns return d # find 8 adjacent odd numbers that sum to a perfect square odd = numbers(8, irange(1, 399, step=2)) # find 7 adjacent even numbers that sum to a perfect square even = numbers(7, irange(2, 399, step=2)) # and look for common sums for k in intersect([odd.keys(), even.keys()]): printf("{k} = {r}^2", r=is_square(k)) printf("{k} = {ns}", ns=odd[k]) printf("{k} = {ns}", ns=even[k]) printf()Solution: The largest numbered house bought was number 118.
The houses bought were:
If the first odd number is (2a + 1), then the odd numbers are:
And this sum is a square, so (a + 4) must be a square number:
If the first even number is 2b, then the even numbers are:
And the sums are equal:
So we can consider possible square numbers for (a + 4) and look for corresponding b values that are integers.
This can be investigated manually or programatically:
Run: [ @replit ]
from enigma import (irange, inf, sq, is_square, printf) # output a list of numbers, sum, and sqrt(sum) def output(t, ns): s = sum(ns) r = is_square(s) printf("-> {t} = {ns} = {s} (= {r}^2)") # consider squares for (a + 4) = i^2 for i in irange(2, inf): a = sq(i) - 4 # calculate b (b, r) = divmod(8 * a + 11, 7) if 2 * b + 12 > 399: break if r != 0: continue # output solution printf("a={a} b={b}") output('odds', list(irange(2 * a + 1, 2 * a + 15, step=2))) output('evens', list(irange(2 * b, 2 * b + 12, step=2)))There is only one a value that gives an integer value for b:
Which gives rise to the two sequences given above.
LikeLike
Frits 10:44 pm on 9 January 2024 Permalink |
b = (8a + 11) / 7 = (8 * (i^2 – 4) + 11) / 7 = (8 * i^2) / 7 – 3
so i^2 must be divisible by 7 and
as variable a can be seen to be less than 168.375 only i = 7 is an option
leading to b = 53 and 2b + 12 = 118
LikeLike
Jim Randell 9:35 am on 10 January 2024 Permalink |
@Frits: Neat.
LikeLike
John Crabtree 4:25 am on 10 January 2024 Permalink |
Let L and R be the integer averages on the left and right sides of the street.
8L = 7R = n^2, which is less than 2800, ie n < 53.
n = 0 (mod (4 * 7)) = 0 (mod 28), and so n = 28 and R = 112.
The highest house number = 112 + 6 = 118.
LikeLike
GeoffR 7:33 pm on 12 January 2024 Permalink |
from math import isqrt def is_sq(x): return isqrt(x) ** 2 == x # Eight odd numbers on left side of the street for n in range(1, 400, 2): L1, L2 = [], [] L1 = [n, n+2, n+4, n+6, n+8, n+10, n+12, n+14] if not is_sq(sum(L1)): continue # Seven even numbers on right side of the street for m in range(2, 402, 2): L2 = [m, m+2, m+4, m+6, m+8, m+10, m+12] if sum(L2) == sum(L1): # Find the largest house number if n+14 > m+12: print('Largest house mumber = ', n+14) else: print('Largest house mumber = ', m+12) # Largest house mumber = 118LikeLike