Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Check if a number is prime by naively checking if its divisible by odd numbers less than its square root
- */
- def isPrimeNaive(n: NT): Boolean = {
- if (n == 2 || n == 3) true
- else if (n % 2 == 0) false
- else (3 until (Math.sqrt(n).toInt + 2) by 2) forall (n % _ != 0)
- }
- /**
- * Works in parallel
- */
- def _makePrimes(N: NT, isPrimeFunc: NT => Boolean): Seq[NT] =
- (3L to N by 2).par.filter(isPrimeFunc(_)).+:(2L).toVector
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement