Tony Stark is, as we know Ironman (that super awesome guy in metal suit and loads of weapons). However, without the metal suit, he can't claim that title. Tony Stark, having a great ego, wants to finish Norseman, which is considered to be the hardest triathlon in the world (for distances equivalent to those of an Ironman race), to prove that he's a mean machine, even when he leaves the iron at home.

Tony has a predefined schedule / time plan for each part of the competition.
That means for every location in the race (i.e. distance from start), there's an expected time he should arrive there based on the schedule.

He also has a watch that tells the time spent and the total distance covered.

Your task is: Given those two values as input, tell Tony how much he is ahead of, or behind schedule. The input will be a time on the format hh:mm:ss (or (optional) h:mm:ss if it's been less than 10 hours) and a decimal number telling how far he has come (in km).

The distances for each of the three disciplines are:

Swim: 3.8 km
Bike: 180 km
Run: 42 km
Total distance: 225.8 km   // Input will never exceed 225.8

The estimated times for each part (i.e. the schedule):

Swim: 1:20:00
Transition 1: 0:12:00
Bike: 7:10:00
Transition 2: 0:05:00
Run: 4:50:00
Total: 13:37:00

Both distances, and the estimated times are given before the race, and can therefore be hardcoded. The transition zone is just a place where he changes clothes and equipment, so he's not moving during transition.

Input can be comma-separated, a string, two separate arguments or whatever is most convenient in your language. He want the output on the format +/-mm:ss, not hours (assume he's never more than one hour too slow or too fast. If he's in transition, you can assume he just got there.

Examples and explanations (apologies for the length of it):

Input: 04:32:20 93.8
Output: +34:40 / 34:40

At 93.8 km, he has finished the swim, been through transition and has finished half of the bike leg. According to the schedule, this should have taken him: 1:20:00 + 0:12:00 + (0.5 * (07:10:00)) = 5:07:00. If he has used 4:32:20, then he's 34:40 ahead of schedule.

Input: 1:20:00 3.8
Output: +00:00 / +0:00 / 00:00 / 0:00 / -00:00 / -0:00

Assuming the distance is 3.8, you can assume he has just got into the first transition zone. The estimated time here was 1:20:00, so for the input above, he's on time.

If the time is 1:25:00, then he's 5 minutes behind schedule, thus:

Input: 1:25:00 3.8
Output: -05:00 / -5:00

Another example, explained in detail:

Input: 10:33:46 198.14

So, a distance of 198.14 km has been covered. That means he has finished the swim (3.8), the bike leg (180 km) and 14.34 km of the running, and he has been through both transitions. According to the schedule, he should have started the run after: 1:20:00 + 0:12:00 + 07:10:00 + 0:05:00 = 8:47:00. 42 km of running should take 4:50:00, thus 14.34 km should take: 4:50:00 * (14.34 / 42) = 1:39:01. So, according to the plan, 198.14 km should take: 8:47:00 + 1:39:01 = 10:26:01. He has used 10:33:46, which is 07:45 more than planned.

Output: -07:45 / -7:45   

The plus sign is optional, but there has to be a minus sign if he's behind schedule.

The output should have exactly the same format as the examples above, but trailing spaces, newlines etc. are OK.

This is code golf, so the shortest code in bytes win.


1 Answer 1


CJam, 91

r~[0_80 3.8_92 43dI183.8 527 290d42]4/{1$a<},W=(@\-\~/@*+60*r':/:i60b-i_gs);\60b2Te[':*)Amd

Try it online. Note: it takes the distance first.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.