Justin Etheredge posted this challenge on CodeThinked so I thought I should give it a try though I’ve just had my TekPub subscription (Looking forward to use it, heavily!! :D)
So here’s my solution:
var myPrimes =
Enumerable.Range(1, SomePositiveValue)
.Where(x => x != 1 &&
!Enumerable.Range(2, (int)Math.Ceiling(Math.Sqrt(x)))
.Any(y => x % y == 0 &&
x != y));
You might want to remove the “x != 1” depending on you consider 1 as a prime or not :)
No comments:
Post a Comment