Back
Close
  • 26

Learning Opportunities

This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.

Statement

 Goal

Swatch Internet Time is a decimal time system introduced in 1998 by Swatch. It is a universal time, expressed as a number between 0 and 1000 named beats representing the time in Biel (UTC+01:00), prefixed by the @ sign.

You are provided with a time and associated timezone, of the format HH:MM:SS UTC[+/-]hh:mm (e.g. 01:23:45 UTC+04:30), and must provide the equivalent in beats, with the format @B.BB (e.g. @123.45). The steps to achieve this are the following:

Step 1. You must obtain the Biel (UTC+01:00) local time from the original time and timezone.
Step 2. You must convert the resulting Biel local time to beats, using the following formula:

(3600 * HH + 60 * MM + SS) / 86.4

Step 3. You must round the result to two decimal places (using half-up rounding), and always present the two decimal digits, e.g. @12.34 and @12.00.

As an example, let's try to convert 21:29:42 UTC+05:30 into beats:

Step 1. We need to convert the time from UTC+05:30 to UTC+01:00. In order to do this, we need to remove 4:30 from the original time, which means we obtain 16:59:42 UTC+01:00.
Step 2. We compute the number of beats, by computing (3600 * 16 + 60 * 59 + 42) / 86.4, which gives us 708.125.
Step 3. We round the result to two decimal places using half-up rounding, which gives us 708.13.

The expected result with this example is @708.13.

Note: Beware of rounding! Your language likely does not use half-up rounding by default, but half-even a.k.a banker's rounding (C/C++, Python, Lua), half-down (JavaScript), and so on, and some tests require the correct rounding algorithm to be set!

Note: Forget about shenanigans such as leap seconds, daylight savings or any other timezone weirdness, stick to the steps presented above!
Input
First line: rawtime being the time with timezone relative to UTC.
Output
First line: Time in beats, of the format @B.BB.
Constraints
length(rawtime) = 18
Example
Input
02:24:00 UTC+01:00
Output
@100.00

A higher resolution is required to access the IDE