Closed FrankKair closed 6 years ago
Straightforward solution, just convert number to big integer and sums its chars as integers.
def solve n = 2.to_big_i (n**1000).to_s.chars.reduce(0) { |sum, char| sum + char.to_i } end
Crystal
Real time: 2.114 s User time: 1.899 s Sys. time: 0.448 s CPU share: 111.04 %
How the solution works
Straightforward solution, just convert number to big integer and sums its chars as integers.
Performance
Crystal