Unlucky odometer
EasyOnline Assessment
Report what a superstitious taxi odometer shows after a given distance.
The odometer shows a whole number of miles with no leading zeros, starting at 0. The garage that built it never uses the digit 4, so whenever the next reading would contain a 4 anywhere (for example 4, 14, 40, 49 or 341) the odometer skips it and moves straight on to the next reading that has no 4. One real mile always advances the display by exactly one allowed reading.
Input: miles, a non-negative integer, the number of real miles driven since the odometer showed 0.
Output: a string, the reading on the display (no leading zeros; "0" when miles is 0).
Example 1
- Input:
- [3]
- Output:
- "3"
- Explanation
- The display shows 0, 1, 2, 3 for the first four miles, so after 3 miles it reads
"3".
Example 2
- Input:
- [4]
- Output:
- "5"
- Explanation
- The readings in order are 0, 1, 2, 3, 5, 6, ... because 4 is skipped. After 4 miles the odometer reads
"5".
Example 3
- Input:
- [39]
- Output:
- "53"
- Explanation
- Below 50 there are only 36 readings without a 4 (tens digit 0 to 3, ones digit anything except 4: 4 x 9), and they cover miles 0 to 35. So mile 36 shows 50, and mile 39 shows
"53".
Constraints
0 <= miles <= 1,000,000,000,000