| Bytes | Lang | Time | Link |
|---|---|---|---|
| 005 | Vyxal 3 | 240901T052825Z | Europe20 |
| 014 | HP‑41C series | 240901T000000Z | Kai Burg |
| 005 | Thunno 2 | 230809T183935Z | The Thon |
| 029 | SageMath | 230414T082439Z | 138 Aspe |
| 020 | Desmos | 230413T202911Z | Youserna |
| 014 | Rattle | 230413T193902Z | Daniel H |
| 016 | Arturo | 230413T193655Z | chunes |
| 014 | Julia 1.0 | 230413T181206Z | Ashlin H |
| 048 | Nibbles | 230413T125315Z | Dominic |
| 045 | GAP | 230413T075339Z | 138 Aspe |
| 046 | Symbolic Python | 171123T144230Z | ovs |
| 033 | PowerShell | 201021T161254Z | Veskah |
| 007 | Husk | 201019T213409Z | LegionMa |
| 007 | 05AB1E | 171114T160643Z | Cinari |
| 036 | C | 171111T160149Z | HatsuPoi |
| 009 | Pushy | 171111T123616Z | FlipTack |
| 025 | REXX | 171113T173551Z | idrougge |
| 034 | Common Lisp | 171113T093636Z | Renzo |
| 013 | Java 8 | 171113T085642Z | Kevin Cr |
| 021 | R | 171113T034820Z | Mark |
| 016 | PARI/GP | 171113T031417Z | Charles |
| 010 | Milky Way | 171112T115150Z | ovs |
| 010 | APL Dyalog | 171111T213448Z | Uriel |
| 029 | Excel VBA | 171111T211553Z | Taylor R |
| 005 | Jelly | 171111T062423Z | Mr. Xcod |
| 028 | Bash bc + sed | 171111T051559Z | Justin M |
| 019 | Labyrinth | 171111T162212Z | Martin E |
| 019 | Alice | 171111T161720Z | Martin E |
| 011 | Retina | 171111T161243Z | Martin E |
| 018 | Haskell | 171111T135212Z | totallyh |
| 020 | bash | 171111T132147Z | Nahuel F |
| 151 | Perl 5 | 171111T131526Z | Nahuel F |
| 023 | Batch | 171111T105417Z | Neil |
| 012 | J | 171111T093134Z | Galen Iv |
| 050 | C gcc | 171111T082320Z | gastropn |
| 010 | dc | 171111T073951Z | seshouma |
| 019 | Python 2 | 171111T064107Z | ovs |
| 006 | Japt | 171111T060530Z | ETHprodu |
| 009 | 05AB1E | 171111T054407Z | user7234 |
| 008 | TIBasic 83 series | 171111T053913Z | Misha La |
| 008 | Pyth | 171111T050354Z | Maltysen |
| 021 | JavaScript | 171111T043458Z | user7234 |
Vyxal 3, 5 bytes
₅y60F
Explanation
₅y60F # Implicit input
₅y # To base 100
60F # From base 60
# Implicit output
HP‑41C series, 14 Bytes
Place the argument in the X register, i. e. on top of stack, and then XEQ M.
01♦LBL⸆M 5 Bytes global label requires 4 + n Bytes
02 1 E2 3 Bytes put 100 on top of stack
03 ∕ 1 Byte X ≔ Y ∕ X
04 HR 1 Byte convert HHMMSS.ss into decimal hours format
05 60 2 Bytes put 60 on top of stack
06 × 1 Byte multiply by number of seconds in minute
07 RTN 1 Byte `RTN` does not affect local label search
The HR conversion function turns a number in HH.MMSSssss format into industry hours (decimal time).
To use it we shift the input’s decimal point two places to the left (100 ∕).
The resulting MM + SS ∕ 60 number needs to be multiplied by 60 to obtain the total time in seconds.
Thunno 2, 5 bytes
ɦB60ḋ
Port of Mr. Xcoder's Jelly answer
Explanation
ɦB60ḋ # Implicit input
ɦB # To base 100
60ḋ # From base 60
# Implicit output
Rattle, 14 bytes
|s/100R1*40$-~
Explanation
| parse input
s save input to memeory
/100 divide by 100
R1 convert to int
*40 multiply by 40
$ swap with value in memory
-~ subtract value in memory from top of stack, print implicitly
Rattle, 18 bytes
|s/100R1*60$%100+~
There's probably some room to reduce the byte count if someone were to pass 100 as a hard-coded argument using 100&\| instead of just |. Yes, that's a challenge!
Explanation
| parse input
s save input to memory slot 0 (also kept on top of the stack)
/100 divide by 100
R1 reformat to int (e.g. 1.52 -> 1)
*60 multiply by 60
$ swap value with the value in storage
%100 mod 100
+~ add this value to the value in storage, print implicitly
Julia 1.0, 14 bytes
~x=x-x÷100*40
Uses the same algorithm as Misha Lavrov's TI-Basic solution.
Julia supports implicit multiplication (40x instead of 40*x), but it takes precedence over most other operators.
Nibbles, 4 bytes (8 nibbles)
`@60`@@
`@ # convert input in command-line arg to base
@ # 100 (default value for @ when no input from STDIN)
`@ # and convert from base
60 # 60
Symbolic Python, 66 48 46 bytes
Thanks to Jo King for -16 bytes!
__=-~-~_-_
_-=_/(__<<__^__)**__*(__-~__<<-~__)
Explanation
# input is initially in _
__=-~-~_-_ # set __ to (2+input-input) = 2
_-= # subtract from _:
_/ # _ divided by:
(__<<__^__)**__ # (2<<2 ^ 2) ** 2 = (8^2)**2 = 100
* # multiplied by
(__-~__<<-~__) # (2 - ~2 << -~2) = 5 << 3 = 40
# value in _ is the implicit output
PowerShell, 38 33 bytes
-5 bytes thanks to mazzy
$args|%{$_-40*($_-replace'..?$')}
Uses the same formula popularizes by ovs. Truncating is still expensive in PowerShell. Now uses a better regex to instead rip the last one or two characters off to division.
Husk, 7 bytes
B60B100
Try it online! Not very exciting, just converts to base 100 and back from base 60.
05AB1E, 7 bytes
т‰ć60*+
Explanation
command current stack
т‰ć60*+ full program. push input implicitly [1234]
т push 100 [1234] [100]
‰ push divmod [12, 34]
ć push head extracted (n[1:], n[0]) [34] [12]
60* multiply by 60 [34] [720]
+ add and display implicitly [754]
C, C++, Java, C#, D : 36 bytes
D : 35 bytes
C : 28 bytes
First time i have an answer that short !
int r(int i){return i/100*60+i%100;}
D can have a special optimization because of the golfy template system :
T r(T)(T i){return i/100*60+i%100;}
C has a special optimization with the implicit int :
r(i){return i/100*60+i%100;}
Code to test
In C ( have to include stdio.h ) :
int main() {
int testArr[] = {1,11,111,1111,9,99,999,9999};
for(int i=0;i<8; ++i) {
printf("%d = %d\n",testArr[i],r(testArr[i]));
}
return 0;
}
In C++ ( have to include iostream ) :
int main() {
std::initializer_list<int> testList{
1,11,111,1111,9,99,999,9999
};
for (auto x : testList) {
std::cout << r(x) << '\n';
}
}
In Java :
public class MainApp {
int r(int i){return i/100*60+i%100;}
public static void main(String[]a) {
MainApp m = new MainApp();
int testArr[] = new int[]{
1,11,111,1111,9,99,999,9999
};
for (int v : testArr) {
System.out.println(v + " = " + m.r(v));
}
}
}
In C#
class Program {
int r(int i){return i/100*60+i%100;}
static void Main(string[] args) {
var p = new Program();
int[] testArr = new int[8]
{
1,11,111,1111,9,99,999,9999
};
foreach(int a in testArr) {
Console.WriteLine(a + " = " + p.r(a));
}
}
}
In D ( have to import std.stdio ) ( exactly, i have no idea how to use arrays in D ) :
void main() {
int[] arr = [1,11,111,1111,9,9,999,9999];
for(int i = 0; i < arr.length; i++)
writeln(arr[i]," = ",r(arr[i]));
}
Pushy, 10 9 bytes
Kevin outgolfed me in my own language... (using the approach from ovs' answer)
2dH/40*-#
10 bytes
sjvj60*^+#
s \ Split input into digits
jvj \ Join the first two and the last two
60* \ Multiply the first by 60
^+ \ Add the values
# \ Print
11 bytes
For one byte more we can use the Input % 100 + 60 * ⌊Input / 100⌋ approach:
H2d%}/60*+#
REXX, 25 bytes
arg t
say t%100*60+t//100
(Just another translations of @ovs)
PARI/GP, 16 bytes
Straightforward:
n->n\100*60+n%100
Unfortunately this nice method is simply too long to use:
n->[60,1]*divrem(n,100)
Milky Way, 10 bytes
':Z/v40*-!
usage: ./mw code.mwg -i 9999
Explanation:
code explanation stack
' push input to stack [input]
: duplicate ToS [input, input]
Z push 100 [input, input, 100]
/v integer division (divide and floor) [input, ⌊input/100⌋]
40 push 40 [input, ⌊input/100⌋, 40]
* multiply [input, ⌊input/100⌋*40]
- subtract [input - ⌊input/100⌋*40]
! print
APL (Dyalog), 11 10 bytes
60⊥0 100⊤⊢
How?
0 100⊤ - encode in base 100, stopping at the second LSB, effectively producing n ÷ 100, n % 100.
60⊥ - decode in base 60
Excel VBA, 29 Bytes
Anonymous VBE immediate window function that takes input from range [A1] and outputs to the VBE immediate window.
?[A1]Mod 1E2+60*[Int(A1/100)]
Jelly, 5 bytes
As a monadic link (thanks for the heads-up, caird!):
b³ḅ60
... Or as a full program:
bȷ2ḅ60
This can be ported easily to 05AB1E, so:
05AB1E, 5 bytes
тв60β
Simply converts the input integer to base 100 and then converts the result from base 60 to integer. Hence, it is equivalent to Input % 100 + 60 * ⌊Input / 100⌋
Bash bc + sed, 30 28 bytes
-2 bytes thanks to @seshoumara.
bc<<<0`sed 's/..\?$/*60+&/'`
Takes input from stdin. Went for a more creative approach: inserts *60+ before the last 1 or 2 digits, and prepends a 0 to the beginning to account for inputs with only 1 or 2 digits. The result is then passed to bc.
Labyrinth, 19 bytes
?:_100%}#00/_60*{+!
Explanation
? Read input.
: Duplicate.
_100% Mod 100.
} Move off to auxiliary stack.
#00/ Divide by 100, using the stack depth to get a 1, instead of _1.
_60* Multiply by 60.
{+ Retrieve the earlier result and add it.
! Print.
The IP then hits a dead end and starts moving backward. When it reaches the / it attempts a division by zero which terminates the program.
Alice, 19 bytes
/o
\i@/.'d%~'d:'<*+
Explanation
Too bad I removed divmod from the language, I guess...
/o
\i@/...
This is just the usual framework for linear programs with decimal I/O operating purely in Cardinal (arithmetic) mode.
. Duplicate input.
'd% Mod 100.
~ Swap with other copy.
'd: Divide by 100.
'<* Multiply by 60.
+ Add.
Retina, 11 bytes
.{100}
60$*
Input and output in unary. The test suite converts from and to decimal for convenience.
Doing this kind of base conversion for only up to two digits is surprisingly simple to do in unary. We just match runs of 100 1s and replace them with 60 1s. Anything that's left over would correspond to the last two digits in the decimal representation and remains unchanged.
Haskell, 18 bytes
f t=t-t`div`100*40
Anotha port.
Pointfree solution, 21 bytes
(-)<*>(*40).(`div`40)
Perl 5, 15+1(-p) bytes
/..$/;$_-=40*$`
- -l switch not counted because for tests readability
Batch, 23 bytes
@cmd/cset/a%1-%1/100*40
J, 12 bytes
-40*&<.%&100
It's ovs' Python 2 solution expressed in J. It consist of a hook and a fork:
┌─┬───────────────────────┐
│-│┌──┬────────┬─────────┐│
│ ││40│┌─┬─┬──┐│┌─┬─┬───┐││
│ ││ ││*│&│<.│││%│&│100│││
│ ││ │└─┴─┴──┘│└─┴─┴───┘││
│ │└──┴────────┴─────────┘│
└─┴───────────────────────┘
%&100 - divides the number by 100
*&<. - finds the floor of the left argument and multiplies it to the left arg.
40 -
- - subtracts the result of the above fork from the input
dc, 10 bytes
?9A~r60*+p
Explanation: in dc when you push sth. on the stack it goes on top
? # read and push the input number on the stack
9A # push 100: 9 * 10^1 + A[10] * 10^0 :D
~ # divide 2nd nr. by the top nr., push quotient, then remainder
r60* # swap top 2 nr., then multiply the top by 60
+p # add top 2 nr., then print result
Japt, 6 bytes
ìL ì60
Test it online! ìL converts to base-100, and ì60 converts back to base 60, resulting in floor(n/100)*60 + n%100. Also works with hours (10000 -> 3600, the number of seconds in an hour).
05AB1E, 9 bytes
т÷60*¹т%+
Explanation:
т÷60*¹т%+
т // Push number 100
÷ // Integer division with the input
60 // Push number 60
* // Multiply with the previous result
¹ // Push input
т // Push 100 again
% // Modulo
+ // Add the first and the second result
Probably there is some trick with base conversions which can be achieved in 05AB1E, but I couldn't find it.
TI-Basic (83 series), 8 bytes
Ans-40int(sub(Ans
Requires OS version 1.15 or higher.
Pyth - 9 8 bytes
Converts input to base 100, then interprets that as a base 60 number.
ijQ*TT60
