010 Summation of primes.sf 422 B

1234567891011121314151617181920212223
  1. #!/usr/bin/ruby
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Website: https://github.com/trizen
  5. # The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
  6. # Find the sum of all the primes below two million.
  7. # https://projecteuler.net/problem=10
  8. # Runtime: 1.255s
  9. func sum_primes(limit) {
  10. var sum = 0
  11. for (var p = 2; p < limit; p.next_prime!) {
  12. sum += p
  13. }
  14. return sum
  15. }
  16. say sum_primes(2e6)