Skip to content

Instantly share code, notes, and snippets.

@cullen-tsering
Created August 12, 2016 18:35
Show Gist options
  • Save cullen-tsering/f8bbbb0671934580666612f2791a3175 to your computer and use it in GitHub Desktop.
Save cullen-tsering/f8bbbb0671934580666612f2791a3175 to your computer and use it in GitHub Desktop.
/*
ways to calculate the number of blocks of used to build a pyramid
*/
var numberOfBlocksInPyramid = function(edgeLength,intialCount) {
if (edgeLength==0) return intialCount;
var atLevel=edgeLength*edgeLength;
console.log(edgeLength + " " + atLevel + " " + intialCount);
intialCount=atLevel+intialCount;
return numberOfBlocksInPyramid(--edgeLength, intialCount);
}
console.log("Level @LevelCount Balance");
console.log("Total: " + numberOfBlocksInPyramid(210,0));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment