Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A simple solution to finding the difference of the "square of the sums" and the "sum of the squares."
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
You can’t perform that action at this time.