Skip to content

Instantly share code, notes, and snippets.

@johana-star
Created May 26, 2011 17:24
Show Gist options
  • Save johana-star/993557 to your computer and use it in GitHub Desktop.
Save johana-star/993557 to your computer and use it in GitHub Desktop.
Euler Project Problem #006
# Solution to Project Euler's sixth problem
# http://projecteuler.net/index.php?section=problems&id=6
# Find the difference between the square of the sum of the first hundred natural numbers and the sum of their squares.
def sum_squares(ceiling)
sum = 0
(1..ceiling).each {|n| sum = sum +n**2}
return sum
end
def square_sums(ceiling)
sum = 0
(1..ceiling).each {|n| sum = sum +n}
return sum**2
end
number = 100
sum_of_squares = sum_squares(number)
square_of_sums = square_sums(number)
puts square_of_sums - sum_of_squares
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment