Skip to content

Instantly share code, notes, and snippets.

@johana-star
Created May 27, 2011 21:56
Show Gist options
  • Save johana-star/996269 to your computer and use it in GitHub Desktop.
Save johana-star/996269 to your computer and use it in GitHub Desktop.
Euler Project Problem #048
# Solution to Project Euler's forty-eighth problem
# http://projecteuler.net/index.php?section=problems&id=48
# Find the last ten digits of the sum of the sequence 1^1, 2^2, 3^3 ... 1000^1000.
def generate_array(number=1000)
array = (1..number).to_a
array.each_with_index do |exp, i|
array[i] = exp**exp
end
return array
end
def sum_array(array)
sum = 0
array.each {|n| sum = sum + n}
return sum
end
array = generate_array
sum = sum_array(array)
p sum.to_s.slice(-10..-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment