Skip to content

Instantly share code, notes, and snippets.

@AndrewGuard
Created January 10, 2014 19:06
Show Gist options
  • Save AndrewGuard/8360492 to your computer and use it in GitHub Desktop.
Save AndrewGuard/8360492 to your computer and use it in GitHub Desktop.
# Problem #6 from http://projecteuler.net/problems
num = 10
def sum_of_squares(num)
sum_of_squares = 0
num.downto(1) do |number|
sum_of_squares += number * number
end
sum_of_squares
end
def square_of_sums(num)
sum = 0
num.downto(1) do |number|
sum += number
end
square_of_sums = sum * sum
square_of_sums
end
def difference(num)
difference = square_of_sums(num) - sum_of_squares(num)
puts difference
end
sum_of_squares(num)
square_of_sums(num)
difference(100000000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment