Skip to content

Instantly share code, notes, and snippets.

@ballpointcarrot
Created April 20, 2011 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ballpointcarrot/931685 to your computer and use it in GitHub Desktop.
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."
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