27
2
Imagine the following 24-hour clock that can be controlled by arrow keys:
╔══╗ ┌──┐
║00║:│00│
╚══╝ └──┘
HH mm
Pressing the up arrow twice (↑↑
) will increase the currently focused hour input:
╔══╗ ┌──┐
║02║:│00│
╚══╝ └──┘
HH mm
Pressing the right arrow (→
) will focus the other input.
┌──┐ ╔══╗
│02│:║00║
└──┘ ╚══╝
HH mm
Pressing the down arrow thrice (↓↓↓
) will now decrease this input.
┌──┐ ╔══╗
│02│:║57║
└──┘ ╚══╝
HH mm
Shortly put:
- The up arrow (
↑
) will increase the currently active input. - The down arrow (
↓
) will decrease the active input. - The right arrow (
→
) will move focus to the right input. - The left arrow (
←
) will move focus to the left input. - Up and down movement will loop around as expected for a time input.
- Left and right movement don't loop around.
The challenge
The clock starts out at 00:00
with the hour input active (see first schematic). Given a list of input commands, output the resulting time in HH:mm
format.
Input can be either a string or a list (or your language equivalent), where the different input directions can be one of the below options:
↑↓←→
udlr
^v<>
- actual arrow key presses if your program has a GUI
Standard loopholes apply.
Test cases
↑↑→↓↓↓ = 02:57
↓→↑←↑→↓ = 00:00
↓→→↓ = 23:59
←←←←→↑ = 00:01
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓→↓ = 23:59
Does one have to use the four specified input direction to value mappings or can one freely choose four different unique values? – Jonathan Frech – 2018-07-18T11:20:36.040
Related – Shaggy – 2018-07-18T11:20:43.060
1@JonathanFrech One of the given options, choosing any four unique values (for example
0123
) would make the challenge a lot easier in certain languages while not benefitting others. – Nit – 2018-07-18T11:21:27.6531@LuisfelipeDejesusMunoz Yes, that's actually written out under the input rules. – Nit – 2018-07-18T11:45:16.433
@Arnauld What about
(h+24e9)%24
which works in practice but not in theory? – l4m2 – 2018-07-18T11:53:25.727@Arnauld Thanks for the idea, added. – Nit – 2018-07-18T11:53:42.537
@l4m2 Given that it would require an input string of ~22 GB to make it fail, I'd personally say that's an acceptable hack. – Arnauld – 2018-07-18T12:24:11.207
3I think this would have been more challenging if it included seconds. This would have more logic behind which one is currently in focus – Jo King – 2018-07-18T12:40:39.203
3Missing a special rule to handle Konami code. – coredump – 2018-07-20T14:02:43.697
1@coredump Considered it, but it would probably take more space than the core of the answer in most languages. – Nit – 2018-07-20T18:51:18.727