Problem 45394. Count the number of folds needed to pack a large sheet
In a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:
- Lay down a large sheet of paper of size X-by-Y feet.
- Fold the sheet in half so that the larger length between X and Y is halved and the other length remains the same.
- Repeat step 2 until both lengths X and Y are less than 1 foot.
For this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 <= X <= 4000 and 1 <= Y <= 4000.
As an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -> (4,2.5) -> (2,2.5) -> (2,1.25) -> (1,1.25) -> (1,0.625) -> (0.5,0.625). We stop because both sizes are now less than 1. This takes a total of 6 folds.
Solution Stats
Problem Comments
-
3 Comments
Even if on the MATLAB software I can prove that my code works, here, I get the error that the server runs out of time. Can someone please help me with this?
It happens sometimes. You can just try later.
Yes, this happens a lot. just for chemical engineering problem.
Solution Comments
Show commentsProblem Recent Solvers108
Suggested Problems
-
Return the 3n+1 sequence for n
8357 Solvers
-
We love vectorized solutions. Problem 1 : remove the row average.
836 Solvers
-
924 Solvers
-
803 Solvers
-
6505 Solvers
More from this Author19
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!