Created
November 9, 2017 15:59
-
-
Save pfcoperez/95fb138c8cf9ac77a01780523dc6c02a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
val upperBound = 100 | |
val candidates = sc.range(1, upperBound) | |
val factors = sc.range(1, math.sqrt(upperBound).toLong+1) | |
val primes = { | |
candidates.cartesian(factors) filter { | |
case (candidate, factor) => candidate % factor == 0L | |
} | |
}.aggregateByKey(0L)((counter, _) => counter+1L, _ + _).filter(_._2 <= 2L).keys | |
// How many primes are under the number 100? | |
primes.count | |
// Let's get 15 first... | |
primes.sortBy(identity).take(15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment