Created
July 3, 2012 00:04
-
-
Save pjc/3036526 to your computer and use it in GitHub Desktop.
Euler Project in Ruby - Problem 10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = 2_000_000 | |
def prime? x | |
(2...x).each { |i| return false if x % i == 0 } | |
true | |
end | |
def primes upto | |
a = [] | |
(2..upto).each { |i| a << i if prime? i ; puts i } | |
a | |
end | |
def array_sum a | |
sum = 0 | |
a.each { |i| sum += i } | |
sum | |
end | |
puts "#{array_sum primes x}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
array_sum can be written simply as