FrankKair / polyglot-euler

📜 Project Euler solutions in various programming languages
MIT License
74 stars 14 forks source link

Crystal 016 #54

Closed FrankKair closed 6 years ago

FrankKair commented 6 years ago

How the solution works

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

Performance

Crystal

Real time: 2.114 s
User time: 1.899 s
Sys. time: 0.448 s
CPU share: 111.04 %