Skip to content

Instantly share code, notes, and snippets.

@martinr448
Last active September 4, 2018 18:23
Show Gist options
  • Save martinr448/ebc3e81eb394eace14df0d0846b9e5d5 to your computer and use it in GitHub Desktop.
Save martinr448/ebc3e81eb394eace14df0d0846b9e5d5 to your computer and use it in GitHub Desktop.
def sum_of_products(a, n):
running_totals = [0] * n
for x in a:
for i in range(n - 1):
running_totals[i] += running_totals[i + 1] * x
running_totals[-1] += x
return running_totals[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment