2015-02-20 09:02:09 -05:00
|
|
|
require "prime"
|
|
|
|
|
|
|
|
|
|
class Integer
|
|
|
|
|
|
|
|
|
|
def popcount
|
2017-09-23 10:01:46 +02:00
|
|
|
to_s(2).count("1") #Ruby 2.4: digits(2).count(1)
|
2015-02-20 09:02:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def pernicious?
|
|
|
|
|
popcount.prime?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
p 1.step.lazy.select(&:pernicious?).take(25).to_a
|
|
|
|
|
p ( 888888877..888888888).select(&:pernicious?)
|