euler/ruby/euler006.rb

12 lines
167 B
Ruby
Raw Normal View History

def sum_squared(n)
2014-04-25 23:59:14 +00:00
(1..n).inject(:+) ** 2
end
def square_sums(n)
(1..n).map { |i| i ** 2 }.inject(:+)
2014-04-25 23:59:14 +00:00
end
def solution
2014-12-05 00:50:52 +00:00
sum_squared(100) - square_sums(100)
end