Skip to content

Commit

Permalink
Problem 92
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbantuelle committed Aug 6, 2018
1 parent 5c9c262 commit 474c005
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions 092.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'pp'

def sum_of_squares(chains, exploration, number)
number = number.to_s
if chains.has_key?(number)
exploration.each do |e|
chains[e] = chains[number]
end
return chains
else
exploration << number
sum = 0
number.each_char { |n|
sum += n.to_i**2
}
return sum_of_squares(chains, exploration, sum)
end
end

chains = {
'1' => '1',
'89' => '89'
}

2.upto(9_999_999) do |i|
chains = sum_of_squares(chains, Array.new, i)
end

puts chains.select{ |k, v| v == '89' && k.to_i < 10_000_000 }.count

0 comments on commit 474c005

Please sign in to comment.