Skip to content

Instantly share code, notes, and snippets.

@mkweick
Created January 19, 2016 02:40
Show Gist options
  • Save mkweick/6c53389464ea08280afa to your computer and use it in GitHub Desktop.
Save mkweick/6c53389464ea08280afa to your computer and use it in GitHub Desktop.
class Squares
attr_reader :max
def initialize(max)
@max = max
end
def square_of_sums
(1..max).inject(:+) ** 2
end
def sum_of_squares
(1..max).map{ |n| n ** 2 }.inject(:+)
end
def difference
square_of_sums - sum_of_squares
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment