Skip to content

Instantly share code, notes, and snippets.

@Sciss
Created October 24, 2016 22:44
Show Gist options
  • Select an option

  • Save Sciss/965088d063f37e3c0789c41fb6a7c472 to your computer and use it in GitHub Desktop.

Select an option

Save Sciss/965088d063f37e3c0789c41fb6a7c472 to your computer and use it in GitHub Desktop.
// quick hack -- no idea if this is elegant or fast
implicit class NextPrime(n: Int) {
def nextPrime: Int =
Iterator.from(n).filter(_.isPrime).next
def isPrime: Boolean = n > 1 && (2 until n).forall(m => n % m != 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment