Last active
August 29, 2015 14:02
-
-
Save Manume/5ec91cc1099fa1343d1e to your computer and use it in GitHub Desktop.
difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
This file contains 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
#difference between the sum of the squares of the first one hundred natural numbers and the square of the sum. | |
class Sum | |
def self.sum(number_set) | |
sum = (number_set).map { |i| i*i }.reduce(:+) | |
#put here the sum of squares of the numbers | |
return sum | |
end | |
def self.square(number_set) | |
square = (number_set).reduce(:+)**2 | |
# put the square of the sum of the numbers | |
return square | |
end | |
def self.difference(number_set) | |
difference = (number_set).reduce(:+)**2 - (number_set).map { |i| i*i }.reduce(:+) | |
return difference | |
end | |
obj=Sum.new | |
output=Sum.difference(1..100) | |
puts"difference between the sum of the squares of the first one hundred natural numbers and the square of the sum is #{output}" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment