Project Euler Problem #9
Okay, this one was tough. Not in the computation – it took me about an hour to refine and submit my solution once I Googled the algorithm; my real problem was in completely understand the requirements of the question, and what it implied. I looked up the Pythagorean triplet, and the history of it.
—
using System;
public class Nine
{
static void Main()
{
int a = 0;
int b = 0;
int c = 0;
for (int i = 2; i < 50; i++)
for (int j = 1; j < i; j++)
{
a = (i * i) - (j * j);
b = 2 * i * j;
c = (i * i) + (j * j);
if (a + b + c == 1000)
{
Console.WriteLine("n{0}n", a * b * c);
break;
}
}
}
}
Categorised as: programming