class String
  def digroot_persistence(base=10)
    num = self.to_i(base)
    persistence = 0
    until num < base do
      num = num.digits(base).sum
      persistence += 1
    end
    [num.to_s(base), persistence]
  end
end

puts 
%w(627615 39390 588225 393900588225).each do |str|
  puts  % [str, *str.digroot_persistence]
end
puts 
format = 
[[, 2],
 [ , 16],
 [, 8],
 [, 36]].each do |(str, base)|
   puts format % [str, base, *str.digroot_persistence(base)]
end