The only weight on person d comes from person b

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

The only weight on person D comes from person B. Person D therefore ends up supporting half of person B’s body weight (100 pounds), plus half of the weight person B is holding up (50 pounds), for a total of 150 pounds, only half of what E is feeling!
Going deeper in the pyramid, how much weight is person H feeling? Well, person H is supporting half of person D’s body weight (100 pounds), half of person E’s body weight (100 pounds), plus half of the weight person D is holding up (75 pounds), plus half of the weight person E is holding up (150) pounds. The net effect is that person H is carrying 425 pounds—ouch! A similar calculation shows that person I is also carrying 425 pounds—can you see why? Person G is supporting half of person D’s body weight (100 pounds), plus half of the weight person D is holding up (75 pounds) or a net total of 175 pounds. Finally, let’s look at person M in the middle of the bottom row. How is she doing? Well, she’s supporting half of person H’s body weight (100 pounds), half of person I’s body weight (100 pounds), half of the weight person H is holding up (212.5 pounds), and half of the weight person I is holding up (also 212.5 pounds), for a net total of 625 pounds! The purpose of this assignment is to become familiar with recursion and solve a problem that is inherently recursive (i.e., it is difficult to figure out how to do it with loops and no recursion). Keep in mind that the first and last people in each row calculate their weight differently than people in interior positions. The weight on any person can be computed recursively, with the base case being the person at the top the person at the top of the pyramid (in row 0), who is shouldering 0 pounds. Requirements 1. Write a recursive function (use no loops), weight_on(r,c) , which returns the weight on the back of the person in row r and and column c . Rows and columns are 0-based, so the top position is (0,0), for example, and person H is in position (3,1). The following also hold: weight_on(0,0) == 0.00 weight_on(3,1) == 425.00
Weights should be floating-point numbers.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture