Problem Statement
You are in charge of programming the hotel elevator.
Many hotel guests consider the digit 4 unlucky. To make their stay more comfortable, the hotel has decided that when numbering the floors it will skip all numbers that contain the digit 4. Thus, the sequence of floor numbers starts as follows: 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39, 50, 51, ...
Suppose a guest entered the elevator in the lobby of the hotel (i.e., floor 0) and pushed the button buttonPressed. We want to send the elevator to the desired floor. Calculate and return the number of physical floors the elevator should ascend.
Definition
- Class:
- LuckyElevator
- Method:
- actualFloor
- Parameters:
- int
- Returns:
- int
- Method signature:
- int actualFloor(int buttonPressed)
- (be sure your method is public)
Constraints
- buttonPressed will be between 1 and 100,000, inclusive.
- buttonPressed will not contain the digit 4.
Examples
3
Returns: 3
The floor number 3 is the actual third floor from the bottom.
5
Returns: 4
When the guest pushes the button number 5, we should bring them to the floor that's fourth from the bottom. (Remember that there is no floor number 4.)
18
Returns: 16
As there is no floor 4 and no floor 14, the button number 18 will bring you to the sixteenth physical floor.
50
Returns: 36
100000
Returns: 59049
This is the largest possible input. The button number 100,000 sends the elevator to the 59,049-th actual floor of the building.
1
Returns: 1
2
Returns: 2
6
Returns: 5
7
Returns: 6
8
Returns: 7
9
Returns: 8
10
Returns: 9
11
Returns: 10
12
Returns: 11
13
Returns: 12
15
Returns: 13
98768
Returns: 58129
98756
Returns: 58118
99887
Returns: 58956
99888
Returns: 58957
89760
Returns: 52290
86722
Returns: 50078
90000
Returns: 52488
76731
Returns: 43525
71717
Returns: 40596