ruby sieve_1_prime_5.rb
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby sieve_1_prime_5.rb相关的知识,希望对你有一定的参考价值。
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]
prime = range.delete_at(0)
primes << prime
range.delete_if { |number| number % prime == 0 }
p "range: #{range}"
puts "==========="
p "primes: #{primes}"
# "range: [7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 49, 53, 59, 61, 67, 71, 73, 77, 79, 83, 89, 91, 97]"
# ===========
# "primes: [2, 3, 5]"
以上是关于ruby sieve_1_prime_5.rb的主要内容,如果未能解决你的问题,请参考以下文章
ruby sieve_1_prime_13.rb
ruby sieve_1_prime_11.rb
ruby sieve_1_prime_7.rb
ruby sieve_1_prime_3.rb
ruby sieve_1_prime_2.rb
ruby sieve_1_tear_down.rb