Created
July 1, 2012 22:43
-
-
Save pjc/3029913 to your computer and use it in GitHub Desktop.
Euler Project in Ruby - Problem 6
This file contains 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
def sum_of_squares upto | |
a = 0 | |
(1..upto).each { |x| a += x**2 } | |
a | |
end | |
def square_of_sum upto | |
a = 0 | |
(1..upto).each { |x| a += x } | |
a**2 | |
end | |
puts square_of_sum(100) - sum_of_squares(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment