ruby sieve_1_prime_2.rb
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby sieve_1_prime_2.rb相关的知识,希望对你有一定的参考价值。
range = (2..100).to_a
primes = []
prime = range.delete_at(0)
primes << prime
range.delete_if { |number| number % prime == 0 }
p "range: #{range}"
puts "==========="
p "primes: #{primes}"
# "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]"
以上是关于ruby sieve_1_prime_2.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_3.rb
ruby sieve_1_tear_down.rb