Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. /**
  2. * Check if a number is prime by naively checking if its divisible by odd numbers less than its square root
  3. */
  4. def isPrimeNaive(n: NT): Boolean = {
  5. if (n == 2 || n == 3) true
  6. else if (n % 2 == 0) false
  7. else (3 until (Math.sqrt(n).toInt + 2) by 2) forall (n % _ != 0)
  8. }
  9.  
  10. /**
  11. * Works in parallel
  12. */
  13. def _makePrimes(N: NT, isPrimeFunc: NT => Boolean): Seq[NT] =
  14. (3L to N by 2).par.filter(isPrimeFunc(_)).+:(2L).toVector
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement