My Alarm Clock
I'm American, and so is my (digital) alarm clock. To set the alarm, it starts at the time it was previously. Hitting the hour button moves it up one hour, and hitting the minute button moves it up one minute. Hitting both buttons at the same time resets it to midnight (12:00 am), and counts as two button presses.
When the hours exceed their cap (12), it resets to 1 and toggles the AM/PM light. When the minutes exceed their cap (59), they reset to 0, without affecting the hours.
The Task
Your task is, given a starting time and a target time, to output the optimal number of buttons presses needed to set my alarm to the target time.
You may take input in whatever format suits you best. The only data your program should need is hours and minutes, for both inputs. That means that you, for example, may take data as milliseconds since epoch, and extract the hours and minutes, but you may not encode anything into the year, month, second, etc. Note that while you may, for example, input using "military time" (or regular time for most of the world), but that doesn't change how my clock works.
Examples
1:15 pm -> 2:30 am
You could push down both buttons to reset to 12:00 am, then increment to 2:30 am, which would be 2+2+30 = 34
button presses. You could also increment to 2:30 am, which would be 13+15 = 28
button presses. Therefore, your output is 28
.
3:58 am -> 4:02 am
You could reset and increment, which would be 2+4+2 = 8
button presses. You could also increment, which would be 1+4 = 5
button presses. Therefore, your output is 5
.
10:55 pm -> 1:00 am
You could reset and increment, which would be 2+1 = 3
button presses. You could also increment, which would be 3+5=8
button presses. Therefore, your output is 3
.
1:00 am -> 1:59 pm
You could reset and increment, but that would be three more presses than just incrementing. Therefore, your output is 12+59 =
71
.
Test Cases
Current Target = Output
1:15pm 2:30am = 28
3:58am 4:02am = 5
10:55pm 1:00am = 3
1:00am 1:59pm = 71
12:00am 12:00am = 0
6:51pm 12:00am = 2
2:01pm 11:00pm = 25
2:01pm 11:01pm = 9
12:59am 12:01am = 2
11:50am 12:00pm = 11