Sha256: c49ca49a803d9bfae852e2ba6fefb7b3f94c4a284e67d1bd7cd5085967cabf20

Contents?: true

Size: 290 Bytes

Versions: 20

Compression:

Stored size: 290 Bytes

Contents

class Integer
  def proth?
    return false if self < 3
    n_max = Math.log2(self-1).ceil
    (1..(self / n_max)).select{|k| k.odd?}.any? do |k|
      (1..n_max).select{|n| 2**n > k}.any? do |n|
        break if (x = (k * (2**n)) + 1) > self 
        x == self
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
numb-0.186.0 lib/numb/proth.rb
numb-0.185.0 lib/numb/proth.rb
numb-0.184.0 lib/numb/proth.rb
numb-0.181.0 lib/numb/proth.rb
numb-0.170.0 lib/numb/proth.rb
numb-0.152.0 lib/numb/proth.rb
numb-0.138.0 lib/numb/proth.rb
numb-0.125.0 lib/numb/proth.rb
numb-0.114.0 lib/numb/proth.rb
numb-0.111.0 lib/numb/proth.rb
numb-0.109.0 lib/numb/proth.rb
numb-0.99.0 lib/numb/proth.rb
numb-0.96.0 lib/numb/proth.rb
numb-0.89.0 lib/numb/proth.rb
numb-0.84.0 lib/numb/proth.rb
numb-0.77.0 lib/numb/proth.rb
numb-0.72.1 lib/numb/proth.rb
numb-0.72.0 lib/numb/proth.rb
numb-0.68.0 lib/numb/proth.rb
numb-0.63.0 lib/numb/proth.rb