Created
April 20, 2011 15:39
-
-
Save ballpointcarrot/931685 to your computer and use it in GitHub Desktop.
A simple solution to finding the difference of the "square of the sums" and the "sum of the squares."
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 sums(n) | |
(1..n).inject(0){|sum,i| sum + i**2} | |
end | |
def squares(n) | |
(1..n).inject(0){|sum, i| sum + i} ** 2 | |
end | |
puts squares(100) - sums(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment