18
1
Related: Program my microwave oven and Generate lazy values.
My colleague is so lazy that he doesn't even bother to move his finger when programming the microwave oven. (This is actually true!)
Help him find the microwave input that gives the time closest to what he wants, but where all digits are the same. If two inputs result in the same time difference from the desired time, choose the one with fewer digits. If both have the same number of digits, choose the lesser – so he doesn't have to wait so long.
Input is the integer that a perfectionist would enter, e.g. 430
is 4 minutes and 30 seconds while 100
and 60
each is 1 minute. It will be greater than 0 and will not exceed 9999.
Output must an integer, e.g. 444
is 4 minutes and 44 seconds and 55
is 55 seconds.
Both input and output may only be in simple seconds (no minutes) if the total time is below 1 minute and 40 seconds.
This is code-golf, so your code must be as short as possible.
Test cases:
30 → 33
60 → 55
70 → 111
90 → 88
100 → 55
101 → 66
120 → 77
130 → 88
200 → 99
201 → 222
500 → 444
700 → 666
1000 → 888
1055 → 999
1056 → 1111
1090 → 1111
3I like the half-lazy approach. Just keep mashing the "add 30 sec" button until it's there :D – Geobits – 2016-02-23T02:53:18.547
@Geobits Awful lot of presses until 11:30. Anyway, the fact is that he uses the method I wrote above... :-D – Adám – 2016-02-23T02:54:41.823
2Yea, I usually just type it in for anything over a few minutes. It's a delicate tradeoff between number of presses and finger-travelling distance ;) – Geobits – 2016-02-23T02:56:25.530
Is input/output in # of seconds allowed? – CalculatorFeline – 2016-02-23T03:06:45.370
2My colleague is so lazy that he doesn't even bother to move his finger when programming the microwave oven. Didn't expect any less from someone working at Dyalog APL headquarters... :) – Lynn – 2016-02-24T16:18:40.660