The sum of smaller prime numbers equal to "n"

In hackealo.co aggain there was another problem and the Ruby solution was easier than I expected.
What is the sum of all primes less than or equal to 5936?
#!/usr/bin/env ruby
require 'mathn'
s=0
Prime.each(5936) do |prime|
     s+=prime
end
puts 'result:'+s.to_s
fuente
Prime Numbers in Ruby

No comments: