I really like times that follow certain patterns. In particular, I like times where all the digits are the same, or all of the digits increase arithmetically by one from left to right. Further, I viscerally hate when people put letters in my times, so all of that AM/PM nonsense is dead to me. Thus, my favorite times are:
0000 0123 1111 1234 2222 2345
For my peace of mind, I need you to write me a single program that, given the current time as input, both: (A) if it is not now one of my favorite times, tells me both (i) how many minutes it's been since my last favorite time as well as (ii) how many minutes from now my next favorite time will occur; and (B) if it is now one of my favorite times, supplies a single 'signal value'.
Your program should accept (by whatever method: function argument,
stdin, command line argument, etc.) the current time, in any of the following formats:
A four-digit time as a string
An integer that can be zero-padded on the left to make a four-digit time as a string
A sequence of four (or fewer) integers, ordered such that the first integer in the sequence is the leftmost (significant) digit in the time input (e.g.,
0951could be validly represented as
[0, 9, 5, 1]or
[9, 5, 1])
0000as a zero-length sequence is acceptable
In the case of a string input, it should only contain digits, no colons or other punctuation. Inputs can be assumed to always be valid 24-hour times:
0 <= HH <= 23 and
0 <= MM <= 59. Disregard the possibility of a leap second.
Your program must supply (function returns,
stdout, etc. are all fine) either (A) or (B), as appropriate to whether or not the input value is a target time.
Supply two numeric values in any sensible format, such as:
Single-string output with a suitable delimiter
Sequential integer/string outputs, e.g.,
bashprinting two lines to
Length-two ordered return values, such as a Python list, a C array, etc.:
The values can come in either order. For example, both of the following would be valid outputs for an input of
49 34 34 49
The order and separator must be the same for all input values, however!
Produce any otherwise unattainable result. The same result must be produced for all six of the target times, however. Infinite loops are excluded.
YAY!!! is used here as a demonstrative example and is not prescriptive.
Input Output ------ -------- 0000 YAY!!! 0020 20 63 0105 65 18 0122 82 1 0123 YAY!!! 0124 1 587 0852 449 139 1111 YAY!!! 1113 2 81 1200 49 34 1234 YAY!!! 1357 83 505 1759 325 263 1800 326 262 1801 327 261 2222 YAY!!! 2244 22 61 2345 YAY!!! 2351 6 9