Created
August 18, 2017 19:39
-
-
Save tomwis/81b420a6825df0a6767f75e95c184257 to your computer and use it in GitHub Desktop.
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
IEnumerable<int> GiveMePrimeNumbers2(IEnumerable<int> numbers) | |
{ | |
return numbers.Where(s => isPrime(s)); | |
bool isPrime(int number) | |
{ | |
if (number < 2) | |
{ | |
return false; | |
} | |
var boundary = (int) Math.Floor(Math.Sqrt(number)); | |
for (int i = 2; i <= boundary; ++i) | |
{ | |
if (number % i == 0) | |
{ | |
return false; | |
} | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment