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