Skip to content

Instantly share code, notes, and snippets.

@nephilim
Last active December 18, 2015 13:29
Show Gist options
  • Save nephilim/5790470 to your computer and use it in GitHub Desktop.
Save nephilim/5790470 to your computer and use it in GitHub Desktop.
Project Euler 10: Summation of Primes
package ysl.p10
object PrimeSum extends App {
def naturals(from: Int): Stream[Int] =
Stream.cons(from, naturals(from + 1))
def sieve(s: Stream[Int]): Stream[Int] =
Stream.cons(s.head, sieve(s.tail filter { _ % s.head != 0 }))
def primes = sieve(naturals(2).takeWhile( _ < 2000000))
// TODO: ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment