Created
May 27, 2011 07:28
-
-
Save johana-star/994799 to your computer and use it in GitHub Desktop.
Euler Project Problem #016
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Solution to Project Euler's sixteenth problem | |
# http://projecteuler.net/index.php?section=problems&id=16 | |
# Find the sum of all the digits in the decimal representation of 2^1000. | |
def generate_array(number) | |
number = number.to_s | |
array = [] | |
(0..number.length-1).each {|n| array.push number.slice(n).to_i} | |
return array | |
end | |
def sum_array(array) | |
sum = 0 | |
array.each {|n| sum = sum + n} | |
return sum | |
end | |
a = Time.new | |
number = 2**1000 | |
digits = generate_array(number) | |
p sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment