Overview

 

Question

\(2^{15} = 32768\) and the sum of its digits is \(3 + 2 + 7 + 6 + 8 = 26\).

What is the sum of the digits of the number \(2^{1000}\)?

click for answer

1366

Solutions

 

Ruby

 exponentSum.rb https://raw.github.com/addamh/euler/master/016/exponentSum.rb download
#!/usr/bin/env ruby

puts (2**1000).to_s.split("").map!{|k| k.to_i}.reduce(:+)
$ time ruby exponentSum.rb
real	0m0.024s
user	0m0.019s
sys	0m0.003s