2014-11-20 19:38:31 +00:00
|
|
|
def sum_squared(n)
|
2014-04-25 23:59:14 +00:00
|
|
|
(1..n).inject(:+) ** 2
|
|
|
|
end
|
|
|
|
|
2014-11-20 19:38:31 +00:00
|
|
|
def square_sums(n)
|
|
|
|
(1..n).map { |i| i ** 2 }.inject(:+)
|
2014-04-25 23:59:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def difference(n)
|
2014-11-20 19:38:31 +00:00
|
|
|
sum_squared(n) - square_sums(n)
|
2014-04-25 23:59:14 +00:00
|
|
|
end
|
|
|
|
|
2014-11-20 19:38:31 +00:00
|
|
|
def solution
|
|
|
|
difference(100)
|
|
|
|
end
|