# pyramid.py - ' Name: Human Pyramids Author: Ethan Balling...

• 2
• 100% (1) 1 out of 1 people found this document helpful

This preview shows page 1 - 2 out of 2 pages.

The preview shows page 1 - 2 out of 2 pages.
'''Name: Human PyramidsAuthor: Ethan BallingDue Date: 11 Feb 2021Course: CS1410-001Details: Given the number of rows in a human pyramid and assuming everyoneinvolved weighs 200 lbs,this program outputs the weight on the back of each member of the pyramid. Thisis done using recursion.Each position is calculated by row and column, putting half the total weight ofthe person above them ontheir back. Can be run using sys.argv or an IDE. Outputs to both the console andpart3.txt'''import sysfrom time import perf_counterfunction_calls = 0cache_hits = 0#Cache Dictionarycache = {}'''Weight_on function uses recursion to calculate weight carried at each positioncalled (r,c)'''def weight_on(r, c):global function_callsglobal cache_hits#Increment number of function callsfunction_calls += 1#Check if (r,c) is in cache and increment cache hitsif (r,c) in cache:cache_hits += 1return cache[(r,c)]#Initialize weight to zeroweight = 0.0#If r and c are 0, means it's at top and no weight carriedif r == 0 and c == 0:return weight

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 2 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
CharlesD.Allison
Tags
Elif Ceylan, Ethan Balling