An easier one… some geometry and Pythog theroem..
I just made a big array, used that as a counter for each solution.. then scanned it to find the answer.
Just remember that the counter is not for c(the hyp) but for the perimeter length (p=a+b+c)…. !
____________
static void Main(string[] args)
{
int[] cc = new int[1001]; //somewhere to store the counts
for (int a = 1; a < 999; a++)
{
for (int b = 1; b < 999; b++)
{
double c = Math.Sqrt(a * a + b * b);
if (c%1==0 && (a+b+c <= 1000)) //must be int length sides and per<=1000
{
cc[Convert.ToInt32(a+b+c)]++;
}
}
}
//now find largest value
int maxp = 0;
int maxn = 0;
for (int i = 0; i < 1000; i++)
{
if (cc[i] > maxn)
{
maxn = cc[i];
maxp = i;
}
}
Console.WriteLine("Answer>>"+maxp + " count of "+maxn);
Console.ReadLine();
}
No comments:
Post a Comment