euler/euler006.rb

21 lines
244 B
Ruby
Raw Normal View History

2014-04-25 23:59:14 +00:00
def sumSquared(n)
(1..n).inject(:+) ** 2
end
def squareSums(n)
sum = 0
for i in 1..n
sum += i ** 2
end
sum
end
def difference(n)
sumSquared(n) - squareSums(n)
end
puts squareSums(10)
puts sumSquared(10)
puts difference(100)