Problem Statement
A package starts at the bottom of an inclined conveyor belt. Every minute, the conveyor belt moves the package up a certain number of feet. Then it pauses so that items on the belt can be inspected. While it is paused, the package slides down the belt a certain number of feet
Given the height of the belt (in feet), the height that a package goes up every minute (in feet), and the height it slides back down during every pause (in feet), return the number of minutes it will take for the package to reach the top.
For example, if the belt is 10 feet high, the belt goes up 3 feet every minute, and falls back down 2 feet during every pause:
During the 1st minute, it will go up to 3 feet and then slide back down to 1.
During the 2nd minute, it will go up to 4 feet and then slide back down to 2.
During the 3rd minute, it will go up to 5 feet and then slide back down to 3.
During the 4th minute, it will go up to 6 feet and then slide back down to 4.
During the 5th minute, it will go up to 7 feet and then slide back down to 5.
During the 6th minute, it will go up to 8 feet and then slide back down to 6.
During the 7th minute, it will go up to 9 feet and then slide back down to 7.
During the 8th minute, it will go up to 10 feet and leave the inclined belt.
Therefore, it would take the package 8 minutes to reach the top.
Definition
- Class:
- Conveyor
- Method:
- move
- Parameters:
- int, int, int
- Returns:
- int
- Method signature:
- int move(int height, int rateUp, int rateDown)
- (be sure your method is public)
Notes
- The package has reached the top when its maximum height is greater than or equal to the height of the belt.
- You need not worry about the package sliding down during the minute that the conveyor belt is moving.
- The first day is day 1.
Constraints
- height will be between 10 and 100, inclusive.
- rateUp will be between 2 and 10, inclusive.
- rateDown will be between 1 and 9, inclusive.
- rateUp will be less than or equal to height.
- rateDown will be less than rateUp.
Examples
10
3
2
Returns: 8
This is the example from above.
100
10
1
Returns: 11
100
2
1
Returns: 99
50
6
2
Returns: 12
92
5
3
Returns: 45
100
10
9
Returns: 91
50
7
5
Returns: 23
26
3
2
Returns: 24
78
8
3
Returns: 15
38
5
2
Returns: 12
88
10
2
Returns: 11
20
2
1
Returns: 19
10
9
8
Returns: 2
10
6
5
Returns: 5
69
9
6
Returns: 21
10
3
2
Returns: 8
10
8
1
Returns: 2
100
6
5
Returns: 95
10
10
1
Returns: 1
11
5
1
Returns: 3
10
7
6
Returns: 4
10
6
1
Returns: 2
10
10
9
Returns: 1
92
5
3
Returns: 45
10
5
2
Returns: 3
14
4
1
Returns: 5
19
7
2
Returns: 4