Sha256: ae1da106cd39cf2a218d6bb8dcfcddb47db3e538d30de2a96845d6636a166ffc

Contents?: true

Size: 313 Bytes

Versions: 16

Compression:

Stored size: 313 Bytes

Contents

# coding: utf-8
class Integer
  def happy?
    return false unless positive?
    n = self
    sad = '4 16 37 58 89 145 42 20'
    seq = ""
    loop do
      n = n.digits.map{|d| d ** 2}.reduce(:+)
      seq << n.to_s  << ' '
      return true if n == 1
      return false if seq.include? sad   
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

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