# Write a microwave timer!

You are an employee of Microteque, a leading Silicon Valley startup creating smart microwave ovens for all kinds of strange places. Your customers can get their microwaves printed with patterns to match their kitchens, campers, man caves; even the kitchens of large nation-state facilities have shiny new branded microwave ovens.

Due to the cutting-edge nature of your microwave control board technology, you've ended up having to use the programming language MicrowaveX* and you're working out how to program the time counter. Your counter looks like this:

Your goal is to write a program that takes the input time and translates it into the number of seconds that the microwave needs to run.

As input, the function must take a string in the format ##:## (including the colon at position 3) and return an integer.

Please note that it should also be able to handle more than 60 seconds in the seconds slot.

Finally, due to some pesky regulations, you cannot have your microwave oven run for more than 100 minutes (6,000 seconds)

Sample inputs and outputs:

01:30 --> 90 seconds

00:66 --> 66 seconds

01:99 --> 159 seconds

02:39 --> 159 seconds

99:99 --> 6,000 seconds (capped at 100 minutes due to aforementioned regulations)

*: MicrowaveX happens to be identical to your programming language of choice, but Microteque has rebranded it to sound more appealing to their investors.

• What's the scoring criteria? Code Golf? May 19, 2020 at 15:41
• 99:99 = 99 min 99 sec is 100 min 39 sec. 100 minutes exactly is 99:60. Is this test case 99:99 intentional or not? (I see it says it would be capped to 100min due to regulations.) May 19, 2020 at 20:47
• I'd love to program in MicrowaveX for this challenge. Care to link to the website of the language?
– user92069
May 20, 2020 at 8:27
• @ Λ̸̸ I think this might be it... scratch.mit.edu Jun 3, 2020 at 22:21
• I once had a microwave that, if you entered 00:60 instead of 01:00, it would say "Error" instead of actually starting the timer. I have no idea why, and I've never seen another one like that since. Aug 8 at 19:55

# K (ngn/k), 14 bytes

Solution:

6000&60/.'":"\


Try it online!

Explanation:

6000&60/.'":"\ / the solution
":"\ / split string on ":"
.'     / value (convert "12" => 12)
60/       / from base-60
6000&          / min of result and 6000


# PowerShell, 50 48 bytes

-2 bytes thanks to mazzy

$a,$b=$args-split':' [Math]::min((60*$a+$b),6e3)  Try it online! • welcome back :) Try it online! Jun 30, 2020 at 16:56 • @mazzy Thanks, it has been awhile. Jun 30, 2020 at 18:44 C# (.NET Core) 77 bytes s=>Math.Min(60*int.Parse(s.Substring(0,2))+int.Parse(s.Substring(3,2)),6000);  It assumes that the position of the colon is always 3 Try it online # C# (.NET Core), 76 bytes s=>Math.Min(s.Split(':').Select(int.Parse).Aggregate((e,i)=>(e*60+i)),6000);  Try it online • Welcome to the site and nice first answer! Be sure to check out our tips for golfing in C# page for any improvements you can find! Jul 3, 2020 at 15:03 • Welcome. Nice first answer! You don't have to count the trailing ; for lambda functions in C#/Java, so that can move to the footer in your TIO. As for golfs, the 6000 can be 6e3 for -1 (the return-type changes from int to double though). :) Enjoy your stay, and good luck with future challenges. Jul 3, 2020 at 15:14 # Java (JDK), 67 bytes t->Math.min(6e3,new Long((t=t[0].split(":"))[0])*60+new Long(t[1]))  Try it online! ## Credits • -4 bytes thanks to Kevin Cruijssen by changing the input type to an array of Strings. • Way longer than what I'd have expected at first. May 20, 2020 at 10:04 • 67 bytes by taking the input wrapped in an array, which is allowed by default according to the meta. Jul 3, 2020 at 15:02 # V (vim), 18 bytes f:i*60<Esc>lr+0C<c-r>=<c-r>" <Esc>  Try it online! # Scala, 66 61 bytes For those who like to live dangerously and assume things beyond a method's contract... io.StdIn.readLine split ":"map(_.toInt)reduce(_*60+_)min 6000  reduce is not guaranteed to work from left to right, but it seems to do so by default. Try it in Scastie # Io, 52 bytes Port of the Python answer. method(x,doString(x split(":")join("*60+"))min(6e3))  Try it online! # R, 46 bytes :=c;min(6e3,eval(parse(t=scan(,"")))%*%60:1)  Try it online! Just redefine : so that we can just use eval to concatenate the hours and minutes together, and do a dot product with c(60,1) to get the seconds. # Dart, 88 bytes import'dart:math';f(s)=>s.split(":").map(int.parse).reduce((v,e)=>min<num>(v*60+e,6e3));  Try it online! # Julia, 71 bytes  function f(x) m,s=parse.(Int,split(x,":")) return min(m*60+s,6e3) end  Try it online! The part which was most interesting to me here, is the parse.() which parses each element in the array. Note the dot operator before the parentheses. Could have knocked off one more byte by putting show() in the function instead of return. But, the footer or output box, on tio, wind up a bit of a mess due to the lack of new lines from show.  function f(x) m,s=parse.(Int,split(x,":")) show(min(m*60+s,6e3)) end  • Welcome to CGCC! It seems like you can remove some of the whitespace: Try it online! – ovs May 21, 2020 at 15:20 • Thanks @ovs, I spent a little while trying to figure out how to make it one line or maybe use the -> anonymous function. But, I don't know Julia that well (this is honestly the first thing I've ever written in Julia.) This is also my first code golf. Should I put you in as current lead? May 22, 2020 at 18:32 The types and the unwrap make this longer than it could be otherwise. # Rust, 121 bytes use std::cmp::min;fn f(s:&str)->i32{let x:i32=s[..2].parse().unwrap();let y:i32=s[3..].parse().unwrap();min(x*60+y,6000)}  Try it online! Explanation: 6000 had to be used because 6e3 is considered a float. 6e3 as i32 is longer than simply using 6000. In production code I would have written it 6_000 but saving the character is the game. min is not imported by default. So we have to pay for that import. parse does the work of other languages type casting. But since it could fail we also need the unwrap. String to int conversions are costly in golf for Rust. Using ? operator could in theory save us the unwrap but then the type for the return needs to be much longer: Result<i32, std::num::ParseError>. That also means the collect has to know about the Result too. We also have to wrap the final return in Ok(). So not much gain there. I looked at using split but it ends up being longer due to working to get the tuple back out of the resulting iterator. # Python 3.8 (pre-release), 56 bytes lambda x:min(int((k:=x.split(":"))[1])+60*int(k[0]),6e3)  Try it online! # Golfscript, 28 bytes ":"/~~\~60*+.6000.@<{\}{}if;  Try it online! # C# (.NET Core) 88 87 bytes s=>{var x=s.Split(':').Select(int.Parse).ToList();return Math.Min(60*x[0]+x[1],6000);};  Try it online Removed trailing newline for 1 byte saving # JavaScript (V8), 47 bytes i=>Math.min(6e3,(i[0]+i[1]-0)*60+(i[3]+i[4]-0))  Call the function with the input string # ARBLE, 31 bytes min(6e3,sub(s,1,2)*60+sub(s,4))  Try it online! # Go 1.21+, 93 92 bytes import."fmt" func f(t string)int{var m,s int Sscanf(t,"%d:%d",&m,&s) return min(6e3,m*60+s)}  Attempt This Online! Uses the brand new builtin min function to save 13 bytes. # Go 1.20.x, 106 104 bytes import."fmt" func f(t string)int{var m,s int Sscanf(t,"%d:%d",&m,&s) o:=m*60+s if o>6e3{o=6e3} return o}  Attempt This Online! • 92 bytes Sep 10 at 15:56 • and 104 bytes for the 1.20.x answer Sep 10 at 15:57 # Thunno 2, 10 bytes ':/60ḋ«ç⁷Ọ  Try it online! #### Explanation ':/60ḋ«ç⁷Ọ '# Implicit input ':/ '# Split it on ":" 60ḋ # Convert from base 60 «ç⁷ # Push 6000 Ọ # Dyadic minimum # Implicit output  # Pure Bash, 35 bytes echo$[s=${1/:/*60+},s>6000?6000:s]  Try it online! # Pure Bash, 36 bytes echo$[(r=\${1/:/*60+})>(b=6000)?b:r]


Try it online!

# Python, 95 Bytes

lambda i: f"Lower"if(int(i[0:2])*60)+int(int(i[3:5]))>6000else(int(i[0:2])*60)+int(int(i[3:5]))


Example Input:

76:92 # String input


Example Output:

4652 # Number of seconds


Note: You do have to call the function and print it separately

Try it online!

• Welcome to Code Golf, and nice answer! Aug 13 at 17:26
• I believe int(int(i[3:5])) could be shortened to remove the redundant int call, right? Aug 13 at 17:34
• Anonymous functions are allowed, so you can remove the f= part to reduce it by 2 bytes. Aug 13 at 18:30

# Desmos, 43 bytes

Takes input in the form of a ASCII code array. Use this to convert testcases to ASCII codes.

f(S)=min(total([600,60,0,10,1](S-48)),6000)


Try it on Desmos!

# Itr, 15 bytes

ê©àé2+à©·+6000m

online interpreter

## Explanation

ê©àé2+à©·+6000m ; implicit input
ê               ; split input into two parts '##:' and '##'
©              ; evaluate the second part to get the number of seconds
à             ; swap
é            ; split of the last character ':'
2+          ; add 2 to ':' (ascii 58) giving 60
à         ; swap
©        ; evaluate the number of minutes
·       ; multiply minutes by 60