2007-12-21 07:05:45 -05:00
|
|
|
! Copyright (c) 2007 Aaron Schaefer, Samuel Tardieu.
|
2007-12-18 20:57:16 -05:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2007-12-21 07:05:45 -05:00
|
|
|
USING: arrays kernel lazy-lists math math.erato math.functions math.ranges
|
|
|
|
namespaces sequences ;
|
2007-12-18 20:57:16 -05:00
|
|
|
IN: project-euler.010
|
|
|
|
|
|
|
|
! http://projecteuler.net/index.php?section=problems&id=10
|
|
|
|
|
|
|
|
! DESCRIPTION
|
|
|
|
! -----------
|
|
|
|
|
|
|
|
! The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
|
|
|
|
|
|
|
|
! Find the sum of all the primes below one million.
|
|
|
|
|
|
|
|
|
|
|
|
! SOLUTION
|
|
|
|
! --------
|
|
|
|
|
2007-12-21 07:05:45 -05:00
|
|
|
! Sieve of Eratosthenes and lazy summing
|
2007-12-18 20:57:16 -05:00
|
|
|
|
|
|
|
: euler010 ( -- answer )
|
2007-12-21 07:05:45 -05:00
|
|
|
0 1000000 lerato [ + ] leach ;
|
2007-12-18 20:57:16 -05:00
|
|
|
|
|
|
|
! [ euler010 ] time
|
2007-12-21 18:29:12 -05:00
|
|
|
! 765 ms run / 7 ms GC time
|
2007-12-18 20:57:16 -05:00
|
|
|
|
|
|
|
MAIN: euler010
|