Skip to content

Instantly share code, notes, and snippets.

@AlexVPopov
Created September 24, 2013 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexVPopov/6684055 to your computer and use it in GitHub Desktop.
Save AlexVPopov/6684055 to your computer and use it in GitHub Desktop.
Project Euler 6b
# Sum of first n numbers is n(n+1)/2
# Sum of squares of first n numbers is n(n+1)(2n + 1)/6
# Expanded form for sum ^ 2 - sum of squares = n^4/4+n^3/6-n^2/4-n/6
def formula(n)
(n ** 4) / 4 + (n ** 3) / 6 - (n ** 2) / 4 - n / 6
end
p formula(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment