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