euler/euler006.rb

21 lines
244 B
Ruby

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)