Name: Anonymous 2013-02-26 14:19
Each rubiks cube is .057 meters on each side. You will write two versions of a function get_numrc that consumes one float greater than zero, height, representing the height of a building in meters, and produces the total number of rubik’s cubes needed to reach that height, if they were stacked one on top of another. You will test get_numrc with varying heights. The output must be the smallest integer X, such that (total height of X rubik's cubes) >= height. For example, if your calculations indicate that 193.2 rubik’s cubes are needed for a building of height 11m, then the function must produce 194. Your function must take into consideration a compression factor that increases for rubik’s cubes closer to the bottom. For instance, if there is one rubik’s cube on top of another rubik’s cube, it will be compressed by a factor of (1-1/100000). If any given rubik’s cube has n rubik’s cubes on top of it, it’s height will be compressed by (1-1/100000)n times its original height.
a) Write a recursive function, get_numrc_a, which calculates the number of rubik’s cubes needed to reach the top of a building with height = height, and a compression factor for each rubik’s cube ((1-1/100000)n).
b) The total number of rubik’s cubes needed, total can also be calculated by the formula: total = log(1-height*(1-comp)/h_rc)/log(comp) where h_rc is the height of a rubik’s cube, comp is the compression factor of (1-1/100000), and height is the height of any given building. Write a non-recursive function get_numrc_b which has the same input and output as part(a). Note: that height and h_rc must be in the same measurement units for this formula to work correctly. You may use math.log, and assume all logarithms are natural logarithms (base e). The tests for part(a) and part(b) should produce the same integer result. However, in part(b) you may test with heights up to 1000m.
For example:
a) Write a recursive function, get_numrc_a, which calculates the number of rubik’s cubes needed to reach the top of a building with height = height, and a compression factor for each rubik’s cube ((1-1/100000)n).
b) The total number of rubik’s cubes needed, total can also be calculated by the formula: total = log(1-height*(1-comp)/h_rc)/log(comp) where h_rc is the height of a rubik’s cube, comp is the compression factor of (1-1/100000), and height is the height of any given building. Write a non-recursive function get_numrc_b which has the same input and output as part(a). Note: that height and h_rc must be in the same measurement units for this formula to work correctly. You may use math.log, and assume all logarithms are natural logarithms (base e). The tests for part(a) and part(b) should produce the same integer result. However, in part(b) you may test with heights up to 1000m.
For example:
get_numrc_a(42.5) => 749
get_numrc_b(20) => 352
get_numrc_b(400) => 7276