rec.puzzles Archive

A street has between 50 and 500 houses numbered 1, 2, 3, ..., N, and there is a house X such that the sum...

arithmetic/house.numbers New

New entry, edited from material collected for the archive and not yet in a released version.

Problem

A street has between 50 and 500 houses numbered 1, 2, 3, ..., N, and
there is a house X such that the sum of the house numbers below X
equals the sum of the house numbers above X.  What is N?

This problem originally appeared in _Strand_ magazine in December 1914.
A friend presented it to Ramanujan, who solved the generalization
mentally in a very short time: he gave all N for which a solution
exists, without the 50 <= N <= 500 constraint.  (Source: Robert
Kanigel, _The Man Who Knew Infinity_, Washington Square Press, p. 214.)

Ramanujan's solution was a continued fraction.  According to him, it
was "obvious" that the solution was a continued fraction, and it was
just a question of figuring out which one it was.

-- Courtenay Footman <cpf@lightlink.com>

[ Editor: the first paragraph and the attribution line are condensed
  by the editor from Footman's posting. ]
Show solution
X = 204 of 288 houses...

There are two solutions for less than 50 houses...
X = 6 of 8 houses,
1 + 2 + 3 + 4 + 5 = 15... X = 6... 7 + 8 = 15
and X = 35 of 49 houses

The next two solutions for more than 500 houses are...
X = 1189 of 1681 houses,  X = 6930 of 9800 houses

-- Brian MacBride <macbride@ix.netcom.com>

Let tri(X) be the sum of the numbers from 1 to X.  The statement of the
problem says that we need to find X and N such that
2tri(X-1) + X = tri(N).  A little manipulation (plus the fact that
tri(X) = X(X+1)/2) turns this into X*X = tri(N).

Therefore, it is necessary and sufficient that you find a number that
is triangular and square.  Never formally studied continued fractions,
but I wouldn't be surprised if there were a method for finding the
solution to this problem using them (like you do for the similar Pell
equations).  Some values of (N,X) for which this works are (1,1),
(8,6), (49,35), (288,204), (1681,1189), (9800,6930), (57121,40391).

-- Matthew Daly <mwdaly@kodak.com>

N = 288 houses.
X is 204; 1+2+...+203 = 20706 = 205+...+288.

Here's how I (and probably Ramanujan) solved it:

First, set up the equation:
 1+2+...+(X-1) = (X+1)+(X+2)+...+N
Using the sum of series formula (the "trapezoid rule"*):
 (X-1)(X)/2 = (N+X+1)(N-X)/2

[* I learned this as the "trapezoid rule" in junior high (or maybe
   independently came up with the explanation; I don't remember).
   Essentially, remember that the area for a trapezoid is
     (base 1 + base 2) * (height) / 2
   Now, a sum of consecutive integers is a lot like a trapezoid;
   for example, to sum 205+206+...+288, imagine a 1x205 rectangle,
   next to a 1x206 rectangle, etc.  When these rectangles are put
   together, you get a really big "trapezoid" with:
     base 1 = 205
     base 2 = 288 [Editor: was "208"]
     height = count(205,206,...288) = 288-205+1 = 84
   just put these in the trapezoidal formula, and you're done!
   This also works for non-consecutive integers, as long as the
   increment is constant.]

But anyway;
 (X-1)(X)/2 = (N+X+1)(N-X)/2
Which we can expand and reduce to:
 2X^2 = N^2 + N
I'd say Ramanujan probably got to this step rather quickly; so far,
it's been pretty straightforward.  It takes a bit of ingenuity to think
of completing the square here:
 8X^2 = 4N^2 + 4N
 2((2X)^2) = (2N+1)^2 - 1
It probably didn't take long for Ramanujan to realize this is a Pell
equation, i.e., an approximation of the square root of 2.
 [If we divide by (2X)^2, we get:
         2N+1  2      1
   2 = ( ---- )  - -------
          2X        (2X)^2   [Editor: denominator was "2X"]
  so (2N+1)/(2X) is a good (and rational) approximation of sqrt(2).]
Now, Ramanujan knew immediately that the solutions to this Pell
equation are the rational approximations to the square root of 2,
which can be calculated from the continued fraction of the square root
of 2:

sqrt(2) = 1+1/(2+1/(2+1/(2+1/(2+...))))

That is, the approximations are:

sqrt(2) =~ 1
sqrt(2) =~ 1+1/2 = 3/2
sqrt(2) =~ 1+1/(2+1/2) = 7/5
sqrt(2) =~ 1+1/(2+1/(2+1/2)) = 17/12
sqrt(2) =~ 1+1/(2+1/(2+1/(2+1/2))) = 41/29
...

[Don't think that Ramanujan did these calculations in his head by brute
force.  He knew he didn't have to, as there are several recursive
relations that do the work:

1+1/(1+1) = 3/2
1+1/(1+3/2) = 7/5
1+1/(1+7/5) = 17/12
1+1/(1+17/12) = 41/29
...

Or perhaps
2x1+1 = 3    2x1+0 = 2
2x3+1 = 7    2x2+1 = 5
2x7+3 = 17   2x5+2 = 12
2x17+7 = 41  2x12+5 = 29
...
]

In any case, every other approximation solves the problem; for
instance, with 17/12, you know that 2N+1 = 17, and 2X = 12; that leads
to N=8 and X=6, or 1+2+3+4+5=7+8.

It's mere arithmetic to build up to the approximation that fits the
conditions, which is 577/408, leading to N=288 and X=204.

Assuming that Ramanujan knew about continued fractions (which means he
knew about Pell's equations), and assuming he was smart enough to
notice the step about completing the square (and every math genius
worth his salt should know that), almost all of the time spent was just
simple arithmetic and some algebraic manipulation.

Or, in his words, the solution was obvious.

ObPuzzle:  36 is a triangular number AND a square number.
  What other numbers are both triangular and square?

ObEasyPuzzle:  Can you show that the previous ObPuzzle is isomorphic to
  the house-numbers puzzle?

ObHardPuzzle:  Can you show that the previous ObPuzzle is isomorphic to
  the house-numbers puzzle WITHOUT using algebra?  I.e., only
  common-sense arithmetic is allowed.

-- Wei-Hwa Huang <whuang@ugcs.caltech.edu>

Let the total number of houses be n and the number of the house in
between be m.  Thus the sum of the numbers 1 to m-1 is equal to the sum
of the numbers m+1 to n.  The first sum is m*(m-1)/2, and the second
sum is n*(n+1)/2-m*(m+1)/2.  This means that
m*(m-1) = n*(n+1)-m*(m+1), i.e. m^2 = n*(n+1)/2.

As n and n+1 have no common factors, either n or n+1 equals a^2, where
a is an integer.  In either case a is a factor of m, i.e. m = a*b.
Thus in the first case b^2 = (n+1)/2 = (a^2+1)/2.  In the second case
b^2 = n/2 = (a^2-1)/2.

Conversely, if b^2 = (a^2+1)/2, then m = a*b and n = 2*b^2-1 satisfy
the original equation, and if b^2 = (a^2-1)/2, then m = a*b and
n = 2*b^2 satisfy the original equation.

If we define a0 = 1 and b0 = 1, then a0^2 = (b0^2+1)/2.  We now
recursively define a<n+1> = an+bn and b<n+1> = 2*an+bn.  Thus a1 = 2
and b1 = 3, and therefore a1^2 = (b1^2-1)/2.  In general
an^2 = (bn^2+(-1)^n)/2.

Proof (by induction):
2*a<n+1>^2 = 2*(an+bn)^2 [Editor: was "(an+bn)^2"]
           = 2*an^2+4*an*bn+2*bn^2 = 4*an*bn+3*bn^2+(-1)^n.
b<n+1>^2 = (2*an+bn)^2 = 4*an^2+4*an*bn+bn^2 = 4*an*bn+3*bn^2+2*(-1)^n.
Therefore a<n+1>^2 = (b<n+1>^2+(-1)^(n+1))/2.

This way an infinite series of solutions can be obtained.  Furthermore,
this recursive relation also works in reverse, i.e. if the pair A0 and
B0 yields a solution, so does also the pair A1 = B0-A0 and
B1 = 2*A0-B0, and so on.  Repeating this must result in a pair where
Ak = Bk > 0, but then we must have Ak^2 = (Ak^2+1)/2 or
Ak^2 = (Ak^2-1)/2.  In the first case Ak = Bk = 1, the series given
above.  In the second case Ak = Bk = sqrt(-1) - not valid.

Therefore the only solutions to m^2 = n*(n+1)/2 come from the series
ak, bk, and the first few are tabulated below:

k    a    b        m        n

0    1    1        1        1
1    2    3        6        8
2    5    7       35       49
3   12   17      204      288
4   29   41    1,189    1,681
5   70   99    6,930    9,800
6  169  239   40,391   57,121
7  408  577  235,416  332,928

For the original puzzle n is between 50 and 500, so it must be 288.

-- Ilan Mayer <ilan@isgtec.com>

[ Editor: in Mayer's recursion and table the letters a and b have
  swapped roles relative to his previous paragraph: there n or n+1 is
  a^2, while in the table it is b^2 (k=1: n+1 = 9 = 3^2 = b^2 and
  n = 8 = 2*2^2 = 2*a^2).  The results are unaffected. ]