martedì 2 novembre 2010

Problem 9

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a2 + b2 = c2.

For example, 32 + 42 = 9 + 16 = 25 = 52.

There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
solution = head [a*b*(1000-a-b) | a <- [1..999], b <- [1..999], solveSystem a b]
    where solveSystem x y = 2000*x + 2000*y - (2*x*y) - 1000^2 == 0
Appling a bit of my liceal math I found that the system contains two equations:
  • a2 + b2 - c2 = 0
  • a + b + c - 1000 = 0

From the second equation derive that c = 1000 - a - b that applied to the first equation produce the following equation (some step omitted :-D): 2000*x + 2000*y - (2*x*y) - 1000^2 == 0.


This time it was funny...

Nessun commento:

Posta un commento