Created
February 5, 2017 17:02
-
-
Save maxint137/9dd44b4b54ad07a6b07329d9b9e5f6cc to your computer and use it in GitHub Desktop.
Project Euler #9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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