Sha256: dd20df12530e79d2da79df69d1d800e130d4955c169de33ee9d3adbd7caf6000

Contents?: true

Size: 327 Bytes

Versions: 11

Compression:

Stored size: 327 Bytes

Contents

class Integer
  def factorial
    return 1 if zero?
    (1..self).reduce(:*)
  end

  def factorial?
    divisors = self.divisors.sort
    divisors.each_with_index do |d, i|
      if divisors[i.succ] == d.succ
        return true if d.factorial == self
      else
        return d.factorial == self
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
numb-0.170.0 lib/numb/factorial.rb
numb-0.152.0 lib/numb/factorial.rb
numb-0.138.0 lib/numb/factorial.rb
numb-0.125.0 lib/numb/factorial.rb
numb-0.114.0 lib/numb/factorial.rb
numb-0.111.0 lib/numb/factorial.rb
numb-0.109.0 lib/numb/factorial.rb
numb-0.99.0 lib/numb/factorial.rb
numb-0.96.0 lib/numb/factorial.rb
numb-0.89.0 lib/numb/factorial.rb
numb-0.84.0 lib/numb/factorial.rb