Created
November 23, 2011 17:11
-
-
Save justinvoss/1389243 to your computer and use it in GitHub Desktop.
Tennis Ball Pyramid
This file contains hidden or 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
def pyramid(level): | |
if level == 1: | |
return 1 | |
return (level * level) + pyramid(level-1) | |
assert pyramid(1) == 1 | |
assert pyramid(2) == 5 | |
assert pyramid(3) == 14 | |
print "Tennis balls in a 33-level pyramid: %d" % pyramid(33) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment