Created
May 26, 2011 17:24
-
-
Save johana-star/993557 to your computer and use it in GitHub Desktop.
Euler Project Problem #006
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 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