Optimize primes calculator in ruby