Statistics

Problem Statement for "LuckyElevator"

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

  1. 3

    Returns: 3

    The floor number 3 is the actual third floor from the bottom.

  2. 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.)

  3. 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.

  4. 50

    Returns: 36

  5. 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.

  6. 1

    Returns: 1

  7. 2

    Returns: 2

  8. 6

    Returns: 5

  9. 7

    Returns: 6

  10. 8

    Returns: 7

  11. 9

    Returns: 8

  12. 10

    Returns: 9

  13. 11

    Returns: 10

  14. 12

    Returns: 11

  15. 13

    Returns: 12

  16. 15

    Returns: 13

  17. 98768

    Returns: 58129

  18. 98756

    Returns: 58118

  19. 99887

    Returns: 58956

  20. 99888

    Returns: 58957

  21. 89760

    Returns: 52290

  22. 86722

    Returns: 50078

  23. 90000

    Returns: 52488

  24. 76731

    Returns: 43525

  25. 71717

    Returns: 40596


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: