It's time for more odometer fun. Last problem, my car's odometer hit 56789. It's coming up on 111111 now, which (barring a major miracle) will be the last binary number to ever show up on the odometer. You will be given two numbers - an odometer reading, and a number base. Calculate the number of miles your car will need to travel in order to show the next number that is valid in that base. If your odometer reading is already a valid number in that base, return 0.
For example, your input is an odometer reading of 12341 with a number base of 4. The next odometer reading that would be valid in base 4 is 13000, so the correct answer would be 13000-12341, or 659.
You can assume that the odometer reading is in base 10, the input is numerical and not a string, all numbers will be positive integers, and that your car will last that long without getting read-ended at a stop-light. Happy driving!
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers57
Suggested Problems
-
Find the longest sequence of 1's in a binary sequence.
6857 Solvers
-
281 Solvers
-
13949 Solvers
-
Recurring Cycle Length (Inspired by Project Euler Problem 26)
168 Solvers
-
634 Solvers
More from this Author80
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!