Sha256: 5666089c65227bea9d971a5ab2ad0da837e628a6cfa22d9647bb5dee9278ea6e

Contents?: true

Size: 496 Bytes

Versions: 15

Compression:

Stored size: 496 Bytes

Contents

# coding: utf-8
class Integer
  def untouchable?
    # * The first untouchable integer is 2
    # * Perfect numbers are never untouchable because they can be expressed
    #   as the sum of their own proper divisors
    # * If p is prime, the sum of the proper divisors of p**2 is p + 1;
    #   therefore, no untouchable number is one more than a prime.
    return false if self < 2 or perfect? or (self - 1).prime?
    (1..((self - 1)**2)).none? do |m|
      m.σ - m == self
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
numb-0.152.0 lib/numb/untouchable.rb
numb-0.138.0 lib/numb/untouchable.rb
numb-0.125.0 lib/numb/untouchable.rb
numb-0.114.0 lib/numb/untouchable.rb
numb-0.111.0 lib/numb/untouchable.rb
numb-0.109.0 lib/numb/untouchable.rb
numb-0.99.0 lib/numb/untouchable.rb
numb-0.96.0 lib/numb/untouchable.rb
numb-0.89.0 lib/numb/untouchable.rb
numb-0.84.0 lib/numb/untouchable.rb
numb-0.77.0 lib/numb/untouchable.rb
numb-0.72.1 lib/numb/untouchable.rb
numb-0.72.0 lib/numb/untouchable.rb
numb-0.68.0 lib/numb/untouchable.rb
numb-0.63.0 lib/numb/untouchable.rb