Skip to content

Instantly share code, notes, and snippets.

@AlexVPopov
Last active December 23, 2015 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AlexVPopov/6683896 to your computer and use it in GitHub Desktop.
Save AlexVPopov/6683896 to your computer and use it in GitHub Desktop.
Project Euler 6a
def sum_of_squares(num)
(1..num).inject { |mem, var| mem + var ** 2 }
end
def square_of_sum(num)
sum = (1..num).inject { |mem, var| mem + var }
sum ** 2
end
p square_of_sum(100) - sum_of_squares(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment