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
@havenwood Thanks :-)
Just a small warning: Crystal is not a Ruby compiler. It's a different language (that happens to have almost the same syntax). And it's more limited than Ruby. And it's still in it's early development stage. And we don't know if it will work.
Topaz looks really good too. It's amazing that it's so fast.