Skip to content

Commit

Permalink
Solved HPYNOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
natansh committed Oct 15, 2012
1 parent 0e5a279 commit acffbb3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions HPYNOS/source.rb
@@ -0,0 +1,18 @@
n = gets.chomp.to_i

cache = {}

count = 0
until n == 1 || cache.has_key?(n)
cache[n] = true
n = n.to_s.split('').map(&:to_i).inject(0) do |res, elem|
res += elem * elem
end
count += 1
end

if n == 1
puts count
else
puts "-1"
end

0 comments on commit acffbb3

Please sign in to comment.