Sha256: d8bc0b5f6c7a212e8bf308620e4b659b28551efd513321c0e34906677b5286a8

Contents?: true

Size: 772 Bytes

Versions: 36

Compression:

Stored size: 772 Bytes

Contents

# coding: utf-8
class Integer

  # An automorphic number is a number whose square terminates in the number
  # itself. That is, k is automorphic if the final digits of k<sup>2</sup> are
  # the digits of k.
  #
  # More generally, an <i>n</i>-automorphic number is one of the form
  # <i>nk<sup>2</sup></i> which has its last digits equal to <i>k</i>.
  # <i>n</i> may be supplied as an argument to this method; otherwise it
  # defaults to 1.
  #
  # Returns true if the number is automorphic; false otherwise. Aliased to
  # Integer#curious?.
  #
  #     25.automorphic?    #=> true
  #     9376.automorphic?  #=> true
  #     600.automorphic?   #=> true
  #
  def automorphic?(n=1)
    (n * self ** 2).to_s.end_with? self.to_s
  end
  alias :curious? :automorphic?
end

Version data entries

36 entries across 36 versions & 1 rubygems

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