How many primes less than or equal to n exists?

In hackealo.co there was another problem and Ruby's solution was easier than I expected
How many primes less than or equal to 7293 exits?

#!/usr/bin/env ruby
require 'mathn'
s=0
Prime.each(7293) do |prime|
     s+=1
end
puts 'resultado:'+s.to_s

source


Ruby online
Prime numbers in Ruby

No comments: