Background
In 1960, the 11th General Conference on Weights and Measures defined the Système International d'Unités (SI) Units which scientists still use today.
The metre and the kilogram became standard units in that conference. These were based on powers of 10 (10, 100, 1000, etc.).
For example:
- there are 100 centimetres in one meter
- there are 1000 meters in one kilometer
- there are 1000 grams in one kilogram
Time units
That conference also established the second as the standard unit for time. Now, this is interesting, because this is not based on powers of 10.
- There are 60 seconds in one minute
- There are 60 minutes in one hour
- There are 24 hours in one day
So let's make our own!
In our system, we will have:
- 100 seconds in one minute
- 100 minutes in one hour
- 10 hours in one day
Your task
Given an input of a time (in 24-hour time), convert it to our system (10-hour).
Example:
Input: 12:34:56
First, convert this to a number of seconds:
(12 * 60 * 60) + (34 * 60) + 56 = 45296
We have 100,000 seconds in our system, and in the normal system there are 86,400. We need to adjust for that:
45296 / 86400 * 100000 = 52425.9259259259
We round this to 52426. Note: this must be rounded.
Now, convert back to hours, minutes and seconds. This is easy because our 10-100-100 system lets us just place the colons in: 5:24:26. This is our final answer.
Note: you do not need to insert the colons.
Test cases
You can input and output in any format you want, including just an integer as the output format.
Here are some test cases:
Input Output
12:34:56 5:24:26
00:00:00 0:00:00*
23:59:59 9:99:99
11:11:11 4:66:10
15:25:35 6:42:77
01:02:03 0:43:09*
* In these ones, you do not have to fill the minutes and seconds up to two places: i.e., you may output 0:0:0 and 0:43:9.
This is code-golf, so shortest answer in bytes wins!
-
\$\begingroup\$ Sandbox \$\endgroup\$The Thonnu– The Thonnu2022年10月10日 16:49:22 +00:00Commented Oct 10, 2022 at 16:49
-
14\$\begingroup\$ Historical aside: this decimal time system was officially adopted in France for part of 1794 and 1795. \$\endgroup\$Dingus– Dingus2022年10月10日 22:54:28 +00:00Commented Oct 10, 2022 at 22:54
-
\$\begingroup\$ Related \$\endgroup\$beaker– beaker2022年10月11日 18:16:38 +00:00Commented Oct 11, 2022 at 18:16
-
\$\begingroup\$ In other words, Implement Swatch Internet Time to 1/100th of a Beat. \$\endgroup\$Jeff Zeitlin– Jeff Zeitlin2022年10月12日 11:31:02 +00:00Commented Oct 12, 2022 at 11:31
15 Answers 15
JavaScript (ES6), 33 bytes
Expects (h,m,s) and returns an integer.
(h,m,s)=>(h*60+m+s/60)*625/9+.5|0
How?
By converting to minutes instead of seconds, the final ratio is:
$$\frac{60\times 100000}{86400}=\frac{625}{9}$$
This is one byte shorter than:
(h,m,s)=>(h*3600+m*60+s)/.864+.5|0
05AB1E, (削除) 10 (削除ここまで) 9 bytes
No 05AB1E yet? Let's fix that!
This is a direct port of hakr14's canvas answer.
60βƵOƵ7/*ò
60βƵOƵ7/*ò
60β Convert input from base 60
ƵOƵ7/ Push 125/108
* Multiply input and 125/108
ò Round
Thanks to @TheThonnu for this answer:
60β.864/ò
60β.864/ò
60β Convert input from base 60
.864 Push .864 (108/125)
/ Divide input by 108/125
ò Round
-
1\$\begingroup\$ 9 bytes \$\endgroup\$The Thonnu– The Thonnu2023年01月14日 10:36:57 +00:00Commented Jan 14, 2023 at 10:36
-
1\$\begingroup\$ @TheThonnu So simple, why didn't i think of that? Nicely done, thanks! \$\endgroup\$nextwayup– nextwayup2023年01月16日 12:43:19 +00:00Commented Jan 16, 2023 at 12:43
Factor, 35 bytes
[ 60 * rot 60 / + + 625/9 * round ]
Expects seconds minutes hours as integers. Port of Arnauld's JavaScript answer.
! 56 34 12
60 ! 56 34 12 60
* ! 56 34 720
rot ! 34 720 56
60 ! 34 720 56 60
/ ! 34 720 14/15
+ ! 34 720+14/15
+ ! 754+14/15
625/9 ! 754+14/15 69+4/9
* ! 52425+25/27
round ! 52426
Jelly, 11 bytes
ḅ60÷.864+.Ḟ
A monadic Link that accepts a list of non-negative integers, [h, m, s], and yields a non-negative integer.
Try it online! Or see the test-suite.
How?
ḅ60÷.864+.Ḟ - Link: list of non-negative integers, T = [h, m, s]:
ḅ60 - convert T from base sixty -> 3600*h+60*m+s = seconds
.864 - 0.864 (seconds per "second")
÷ - (seconds) divide (0.864) -> "deconds"
. - a half
+ - (deconds) add (a half)
Ḟ - floor to nearest integer
-
1\$\begingroup\$ You need to add
.432before dividing to round correctly (.5only works after you divide). \$\endgroup\$Neil– Neil2022年10月10日 19:58:48 +00:00Commented Oct 10, 2022 at 19:58 -
1\$\begingroup\$ Oops, that was dumb! Thanks @Neil \$\endgroup\$Jonathan Allan– Jonathan Allan2022年10月10日 22:33:22 +00:00Commented Oct 10, 2022 at 22:33
Python 3, 65 bytes
h,m,s=map(int,input().split())
print(round((h*3600+m*60+s)/.864))
Takes input as HH mm ss and outputs as Hmmss
-3 thanks to Jonathan Allan
-
\$\begingroup\$
/.864saves three bytes. \$\endgroup\$Jonathan Allan– Jonathan Allan2022年10月10日 17:17:07 +00:00Commented Oct 10, 2022 at 17:17
C (GCC), (削除) 73 (削除ここまで) 68 bytes
-5 bytes thanks to @Neil
f(char*x){return((atoi(x)*3600+atoi(x+3)*60+atoi(x+6))*125+54)/108;}
-
-
-
\$\begingroup\$ @jdt you can post it as a new answer if you want, it's basically a new solution (although ported from another language) \$\endgroup\$matteo_c– matteo_c2022年10月14日 13:32:10 +00:00Commented Oct 14, 2022 at 13:32
Charcoal, 13 bytes
I⌊⊘⊕∕↨60A·432
Try it online! Link is to verbose version of code. Takes input as a list. Explanation:
A Input array
↨ Converted from base
60 Literal integer `60`
∕ Divided by
·432 Literal number `0.432`
⊕ Incremented
⊘ Halved
⌊ Floor
I Cast to string
Implicitly print
26 bytes for string I/O:
✂⪫⪪%%06.0f∕↨60I⪪S:·864¦2:1
Try it online! Link is to verbose version of code.
Canvas, 13 bytes
̅-┴ ̅n ×ばつ11⁄2+u
Explanation:
̅-┴ ̅n ×ばつ11⁄2+u | Full code (converted to half-width)
--------------+------------------------------------
̅-┴ | Convert input from base 60
̅n ̅]÷ | Push 125/108
×ばつ | Multiply
11⁄2+ | Add .5
u | Floor
Pyth, 12 bytes
/hyiQ60y.864
Try it online! Input takes a list [hours, minutes, seconds], and outputs an integer.
Explanation:
/hyiQ60y.864 # whole program
Q # take the input
i 60 # and convert it from base 60 to decimal
y # double it
h # increment it
/ # then integer divide it by
y.864 # 0.864 doubled (which is 1.728)
Retina 0.8.2, 40 bytes
\d+
$*
+`1:
:60$*
1
125$*
::
54$*
1{108}
Try it online! Link includes test cases. Explanation: Port of my golf to @matteo_c's answer.
\d+
$*
Convert the hours, minutes and seconds to unary.
+`1:
:60$*
Convert from base 60, by multiplying each 1 by 60 as it passes a : on its way to being a number of seconds.
1
125$*
Multiply by 125.
::
54$*
Add 54.
1{108}
Integer divide by 108 and convert to decimal.
MathGolf, 15 bytes
╚*j╟*++╔/☼*∞)i1⁄2
Inputs as three loose floats, output as a single integer.
Explanation:
Even though MathGolf has single-byte constants for 60, 3600, 86400, and 100000, it's still pretty long because it's missing base-conversion and round builtins, so those have to be done by manually.
╚* # Multiply the first (implicit) input by 3600
j # Get the second input-float
╟* # Multiply it by 60
+ # Add the two together
+ # Also add the third (implicit) input-float
╔/ # Divide this by 86400
☼* # Multiply it by 100000
∞)i1⁄2 # Round it:
∞ # Double this float
) # Increase it by 1
i # Truncate it to an integer
1⁄2 # Integer-divide it by 2
# (after which the entire stack is output implicitly as result)
Thunno, \$ 11 \log_{256}(96) \approx \$ 9.05 bytes
aKAd.864/Zv
Attempt This Online! or verify all test cases
Explanation
aKAd.864/Zv # Implicit input
aKAd # Convert from a list of digits in base-60
.864/ # Divide by .864
Zv # Round to the nearest integer
# Implicit output