Created
September 24, 2013 12:34
-
-
Save AlexVPopov/6684055 to your computer and use it in GitHub Desktop.
Project Euler 6b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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