Sha256: fece3ae770380aa44a6b8e9070c16cb9a672ea960b09f431bcf9af95ad556bab

Contents?: true

Size: 545 Bytes

Versions: 19

Compression:

Stored size: 545 Bytes

Contents

# coding: utf-8
class Integer
  # A Dudeney number is a positive integer that is a perfect cube such that
  # the sum of its decimal digits is the cube root of the number. 
  #
  # Returns true if self is a Dudeney number; false otherwise.
  #
  #     4913.dudeney?  #=> true
  #     5832.dudeney?  #=> true
  #     98.dudeney?    #=> false
  #
  def dudeney?
    # The ugly hack below is seemingly needed for 1.8 compatibility. I ave
    # yet to understand why.
    Math.cbrt(self).to_s.sub(/\.0$/,'') == self.digits.reduce(:+).to_s
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
numb-0.181.0 lib/numb/dudeney.rb
numb-0.170.0 lib/numb/dudeney.rb
numb-0.152.0 lib/numb/dudeney.rb
numb-0.138.0 lib/numb/dudeney.rb
numb-0.125.0 lib/numb/dudeney.rb
numb-0.114.0 lib/numb/dudeney.rb
numb-0.111.0 lib/numb/dudeney.rb
numb-0.109.0 lib/numb/dudeney.rb
numb-0.99.0 lib/numb/dudeney.rb
numb-0.96.0 lib/numb/dudeney.rb
numb-0.89.0 lib/numb/dudeney.rb
numb-0.84.0 lib/numb/dudeney.rb
numb-0.77.0 lib/numb/dudeney.rb
numb-0.72.1 lib/numb/dudeney.rb
numb-0.72.0 lib/numb/dudeney.rb
numb-0.68.0 lib/numb/dudeney.rb
numb-0.63.0 lib/numb/dudeney.rb
numb-0.21.0 lib/numb/dudeney.rb
numb-0.20.0 lib/numb/dudeney.rb