Skip to content

Instantly share code, notes, and snippets.

@justinvoss
Created November 23, 2011 17:21
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 justinvoss/1389272 to your computer and use it in GitHub Desktop.
Save justinvoss/1389272 to your computer and use it in GitHub Desktop.
Tennis Ball Pyramid Part Deux
def pyramid(level):
total = 0
for x in range(1, level+1):
total += (x * x)
return total
assert pyramid(1) == 1
assert pyramid(2) == 5
assert pyramid(3) == 14
print "Tennis balls in a 10,000-level pyramid: %d" % pyramid(10000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment