Project Euler Problem 16
問題
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?
ソース
x = 1000 puts (2 ** x).to_s.scan(/./).map{|x| x.to_i}.inject(:+)
解答
1366
感想
コレはRubyとinjectのお陰!
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?
x = 1000 puts (2 ** x).to_s.scan(/./).map{|x| x.to_i}.inject(:+)
1366
コレはRubyとinjectのお陰!