def is_prime? n
(2...n).all? { |i| n % i != 0 }
end
def sexy_primes n
(9..n).map do |i|
[i - 6, i]
end.select do |i|
i.all? { |i| is_prime? i }
end
end
a = Time.now
sexy_primes 100_000
b = Time.now
puts b - a
7.78 sec
45.38 sec
44.82 sec
41.97 sec
85.51 sec
23.97 sec
35.37 sec
262.25 sec (not compiled or performance optimized, just here for fun)
429.36 sec
Copyright Shannon Skipper MIT or Ruby License
Can I add this script to MRI benchmark directory? (license?)