Skip to content

Instantly share code, notes, and snippets.

@johana-star
Created May 27, 2011 07:28
Show Gist options
  • Save johana-star/994799 to your computer and use it in GitHub Desktop.
Save johana-star/994799 to your computer and use it in GitHub Desktop.
Euler Project Problem #016
# 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