Skip to content

Instantly share code, notes, and snippets.

@Dinner1111
Created November 9, 2014 10:06
Show Gist options
  • Save Dinner1111/83ffde840754154bde3b to your computer and use it in GitHub Desktop.
Save Dinner1111/83ffde840754154bde3b to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
namespace ProjectEuler
{
class Problem_9
{
/*
* A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
*
* a^2 + b^2 = c^2
* For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
*
* There exists exactly one Pythagorean triplet for which a + b + c = 1000.
* Find the product a * b * c
*/
public static void Run()
{
int sum = 0;
int product = 0;
int a = 3, b = 4, c = 5;
for (int multiplier = 2; sum != 1000; multiplier++)
{
sum = a + b + c;
if (sum == 1000)
product = a * b * c;
a *= multiplier;
b *= multiplier;
c *= multiplier;
}
Console.WriteLine(product);
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment