8
3
Challenge:
Your program will take two integers n and k as input, and output the smallest integer greater than (but not equal to) n that contains at least k occurrences of the digit 5.
You can assume 1 ≤ k ≤ 15 and 1 ≤ n < 10**15.
This is a restricted-time challenge. Your program must run on TIO for all of the test cases and complete within 10 seconds in total.
General rules:
This is code-golf, so the shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for any programming language.Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call. The function parameters may be taken in either order, but please specify in your answer.
- Default Loopholes are forbidden.
- You must add a link with a test for your code (i.e. TIO).
- The answer header should list the score in bytes but also the total time taken for all test cases on TIO
- If your language is not on TIO, the code should finish far under 10 seconds on your machine so that you're confident it's fast enough on any reasonable computer.
- Adding an explanation for your answer is highly recommended.
Test Cases:
(n, k) -> output
(53, 2) -> 55
(55, 1) -> 56
(65, 1) -> 75
(99, 1) -> 105
(555, 3) -> 1555
(557, 1) -> 558
(5559, 3) -> 5565
(6339757858743, 5) -> 6339757859555
(99999999999999, 15) -> 555555555555555
Program Example:
This program is correct.
1
Note that timing on TIO is not perfectly reliable, though while insufficient for [tag:fastest-code] it probably suffices for [tag:restricted-time].
– Laikoni – 7 years agoI assume the correct answer for
(n, k) = (45, 1)is50? Some of the answers get this wrong. – Neil – 7 years ago