This is driving me nutty. I'm solving an equation from Diophantus, and I keep ending up with what appears to be wrong, and yet I can't see where. I must be messing up something pretty basic here. Help highly appreciated! Ok, the problem is:

Given a right triangle with area 7 and perimeter 12. Find it's sides.

Let x and y be the sides next to the right angle.

So, the area is $\displaystyle \frac{xy}{2} = 7$ or $\displaystyle xy = 14$ and perimeter is $\displaystyle x + y + \sqrt{x^2 + y^2} = 12$

First, I try to get rid of the radical in the second equation by isolating it on one side and squaring both sides of the equation:

$\displaystyle \sqrt{x^2 + y^2} = 12 - x - y$

$\displaystyle (\sqrt{x^2 + y^2})^2 = (12 - x - y)^2$

$\displaystyle x^2 + y^2 = 144 - 12x - 12y - 12x +x^2 + xy - 12y + xy + y^2$

$\displaystyle 24x - 2xy + 24y - 144 = 0$

I turn the first equation into $\displaystyle y = \frac{14}{x}$ and substitute into the other equation:

$\displaystyle 24x - 2x(\frac{14}{x}) + 24(\frac{14}{x}) - 144 = 0$

$\displaystyle 24x + \frac{336}{x} - 172 = 0$

Multiplying everything by x to get rid of the 336/x, I get:

$\displaystyle 24x^2 - 172x + 336 = 0$

However, the book (The Story of $\displaystyle \sqrt{-1}$) says it's $\displaystyle 336x^2 - 172x + 24 = 0$

I must have made an error but I don't see it. I know I need to go to sleep, but I'll probably be having trouble sleeping with that bothering me.

P.S. Answers are complex, FYI.