Sha256: 05a425c664131342e3e9c1733e1dc8c32e5560bfaec140e7cbb9f3a6d2f7b276

Contents?: true

Size: 300 Bytes

Versions: 16

Compression:

Stored size: 300 Bytes

Contents

# coding: utf-8
class Integer
  def parasitic?(n=nil)
    return (1..9).any?{|x| parasitic?(x)} if n.nil?
    return true if (n == 1 && self == 1)
    return false unless self > 9
    raise ArgumentError unless (n.positive? && n < 10)
    (n*self) == [digits.last, digits[0..-2]].join.to_i
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

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