Created
January 19, 2016 02:40
-
-
Save mkweick/6c53389464ea08280afa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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