Skip to content

Instantly share code, notes, and snippets.

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}
def squares(n)
(1..n).inject(0){|sum, i| sum + i} ** 2
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.