"Yannick Grams" <yannick_grams / hotmail.com> writes:

> Hello to everyone!
>
> I have a mathematic problem I need to solve, and it involves finding
> the values of three consecutive numbers, x, y and z. I need to be able
> to find every instance of these from negative one million (-1,000,000)
> up to one million (1,000,000). They must follow the following
> equations:
>
> x + y + z = 5
> x + y - z = 7
> (x - y)(x - y)(x - y)  + (y - z)(y - z)(y - z) = (x - z)(x - z)(x - z)
>
> I'm completely and utterly stumped. I intend on solving this via Ruby,
> as doing it on pen and paper might take a while. ;) If anyone has any
> suggestions, I'd love to hear them.

This has already been answered by several others, but I'd like to
point out how it could have been solved easily with pencil and paper.

First off, look at the top two equations:

> x + y + z = 5
> x + y - z = 7

These tell you:

(x+y) + z = 5
(x+y) - z = 7

Although you can add the equations and then divide to get there, it
should be obvious at this point that (x+y) is the average of 5 and 7,
that is that x+y=6.  Knowing that, you have that z=-1.

Now, the third equation is:

(x-y)**3 + (y+1)**3 = (x+1)**3

Now, one thing to hold onto is that when you have

   a**n + b**n = c**n

For any integer n > 2, the only way to get a solution with a, b, and c
integers is to have one of a, b, or c be 0. (*) Since a person put
this problem together to be solved, and since pencil-and-paper cubics
are a royal pain in the ass to solve in general if at least one
solution isn't integers, let's see if we can make it work with one of
those three bits we're cubing equal to 0.

First off, see if it'll work with x-y=0 :

  Well, if x-y=0, then x=y and then of course
  (x-y)**3 + (y+1)**3 = (x+1)**3
    0      + (x+1)**3 = (x+1)**3
  So, it'll work if x-y=0.

  Since x+y=6 one solution is then x=3,y=3,z=-1.

Now let's see if it works with y+1=0:

  Well, if y+1=0, then y=-1 and then:
  (x-y)**3 + (y+1)**3 = (x+1)**3
  (x+1)**3 +    0     = (x+1)**3
  So, it'll work if y+1=0.

  Since x+y=6, another solution is x=7,y=-1,z=-1

Now let's see if it works with x+1=0:

  Well, if x+1=0, then x=-1 and then:
  (x-y)**3  + (y+1)**3 = (x+1)**3
  (-1-y)**3 + (y+1)**3 = 0
  So, it'll work if x+1=0.

  Since x+y=6, the final solution is x=-1,y=7,z=-1

Since we're dealing with a cubic and a linear equation once "z" is
solved for with the first two equations, we can only expect to get
at most three solutions, so we're done.  The three possible solutions
are:
  x=3, y=3, z=-1
  x=7, y=-1,z=-1
  x=-1,y=7, z=-1

(*) There's not room in this post to prove that here.

-- 
s=%q(  Daniel Martin -- martin / snowplow.org
       puts "s=%q(#{s})",s.map{|i|i}[1]       )
       puts "s=%q(#{s})",s.map{|i|i}[1]