Skip to content

Instantly share code, notes, and snippets.

@maxint137
Created February 5, 2017 17:02
Show Gist options
  • Save maxint137/9dd44b4b54ad07a6b07329d9b9e5f6cc to your computer and use it in GitHub Desktop.
Save maxint137/9dd44b4b54ad07a6b07329d9b9e5f6cc to your computer and use it in GitHub Desktop.
Project Euler #9
//https://projecteuler.net/problem=9
void Main()
{
int P = 1000;
var t = Enumerable.Range(1,P)
.Select(a => possibleBC(a, P))
.SelectMany(_ => _)
.Where(_=>_.Item2*_.Item2+_.Item3*_.Item3==_.Item1*_.Item1)
.First();
(t.Item1*t.Item2*t.Item3).Dump();
}
IEnumerable<Tuple<int,int,int>> possibleBC(int a, int P)
{
return Enumerable.Range(1, P - a)
.Select(b => new { b = b, c = P - a - b })
.Where(_=> a<_.b+_.c && _.b<a+_.c && _.c < a+_.b)
.Select(_=>new Tuple<int,int,int>(a, _.b, _.c));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment