ruby sieve_1_prime_3.rb

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby sieve_1_prime_3.rb相关的知识,希望对你有一定的参考价值。

range = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39,
        41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75,
        77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99]
primes = [2]
prime = range.delete_at(0)
primes << prime
range.delete_if { |number| number % prime == 0 }

p "range: #{range}"
puts "==========="
p "primes: #{primes}"

# "range: [5, 7, 11, 13, 17, 19, 23, 25, 29, 31, 35, 37, 41, 43, 47, 49, 53, 55, 59, 
# 61, 65, 67, 71, 73, 77, 79, 83, 85, 89, 91, 95, 97]"
# ===========
# "primes: [2, 3]"

以上是关于ruby sieve_1_prime_3.rb的主要内容,如果未能解决你的问题,请参考以下文章

ruby sieve_1_prime_13.rb

ruby sieve_1_prime_11.rb

ruby sieve_1_prime_7.rb

ruby sieve_1_prime_5.rb

ruby sieve_1_prime_2.rb

ruby sieve_1_tear_down.rb