Skip to content

Instantly share code, notes, and snippets.

View mattmahn's full-sized avatar

Matt Mahnke mattmahn

View GitHub Profile
@mattmahn
mattmahn / BallsInPyramid.py
Created August 25, 2013 04:10
Calculates the number of balls stacker in the shape of a triangular pyramid given the number of layers
def count_layer(layer):
""" Returns the number of balls in a layer """
if layer == 0:
return 0
else:
return count_layer(layer-1) + layer
def count_pyramid(numLayers):
currentLayer = 0
numBalls = 0