Skip to content

Instantly share code, notes, and snippets.

@noel-yap
Created August 26, 2020 17:32
Show Gist options
  • Save noel-yap/ad9e11d25bb89931eab66c8bcea2d508 to your computer and use it in GitHub Desktop.
Save noel-yap/ad9e11d25bb89931eab66c8bcea2d508 to your computer and use it in GitHub Desktop.
Sum square difference: https://projecteuler.net/problem=6
#!/usr/bin/python3
import argparse
def sum_of_sequence(n):
return n * (n + 1) / 2
def sum_of_squares_of_sequence(n):
return n * (n + 1) * (2 * n + 1) / 6
parser = argparse.ArgumentParser(description='Difference between sum of squares and square of sum.')
parser.add_argument('n')
args = parser.parse_args()
n = int(args.n)
print(sum_of_sequence(n) ** 2 - sum_of_squares_of_sequence(n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment