# Ring me when our cup noodles are ready [duplicate]

I'm currently cooking us some cup noodles, but we're really sleepy at the moment. They'll be finished in 50 seconds from now, can you wake me up then?

## Problem:

Write a program or function that waits 50 seconds of busy waiting (so that you too doesn't sleep) and then outputs at least 1 visible character to wake me up.

## Busy waiting:

You can't use functions like sleep or delay or pause to wait for the 50 seconds, you have to keep checking the elapsed time.

## Rules:

• Your code must be somewhat consistent in time, between runs and between computers. A small error of +- 1 seconds is acceptable.
• You can't output any visible characters between 1 and 50 seconds (let me sleep).
• Whitespace characters (newline, space, tab, ...) are not considered visible characters for this challenge.
• This is , so shortest code wins.

## marked as duplicate by Beta Decay, Blue code-golf StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); May 20 '17 at 10:33

• Can the output be non-deterministic (something different every time)? – Comrade SparklePony May 7 '17 at 14:49
• @ComradeSparklePony if it always outputs at least 1 visible character, sure – Felipe Nardi Batista May 7 '17 at 14:50
• The problem with this approach is the risk that the CPU fan will wake you up early... – Neil May 7 '17 at 15:35
• Is it ok to reboot the machine after printing the "visible characters"? – Matteo Italia May 7 '17 at 16:24
• @TheLethalCoder it can be a value returned by a method, but when printed must have at least 1 visible character – Felipe Nardi Batista May 8 '17 at 14:33

# MATL, 7 bytes

1Z50<

### Explanation

1        % Push 1
        % Do...while
Z     %   Elapsed time since program started
50     %   Push 50
<      %   Less than?
% End (implicit). The loop continues if top of the stack is truthy
% Display (implicit)
• I think this code is pretty self-explanatory. – Erik the Outgolfer May 7 '17 at 14:56
• @Erik And very similar to Stewie's answer. Anyway I'll add an explanation later – Luis Mendo May 7 '17 at 15:04

# Octave, 22 21 bytes

Saved one byte by changing from while ... end to do ... until.

tic;do
until toc>50;1

tic starts a timer, while toc returns the number of decimal seconds since the last call to tic. We initiate a do - until loop, where we'll loop until toc>50, doing nothing inside the loop. The loop stops after 50 seconds, followed by ans = 1 on the screen.

Try it on TIO (time changed to 5 seconds) or paste it into Octave Online.

• Does this also work in Octave online? – Michthan May 8 '17 at 10:06
• @Michthan yes. Links added to TIO and Octave Online. I recommend choosing a lower time than 50 seconds when testing it :) – Stewie Griffin May 8 '17 at 10:24

# Lua, 35 bytes

while os.clock()<50 do end;print'!'

odd thing is that it has exactly the same length as:

repeat until os.clock()>50;print'!'

Try it online!

• I don't know Lua, but can't you print a number and save 2 bytes? – totallyhuman May 8 '17 at 20:41
• For @totallyhuman and those curious: print 2 results in a syntax error, whereas print'!' will print !. See section 3.4.10 of the lua manual. Arguments have the following syntax: ‘(’ [explist] ‘)’ | tableconstructor | LiteralString (I shortened the BNF because line breaks don't work in comments) – Finn O'leary May 8 '17 at 20:58

# TI-Basic, 14 12 bytes

startTmr
While 50>checkTmr(Ans
End

(Ab)uses the fact that TI programs output Done if nothing is evaluated on the last line.

• I'm new to golfing, so can you explain to me how this is 12 bytes. I count 35. Thx. – gogators May 11 '17 at 18:03
• @gogators Check out this answer I wrote on this subject, it will explain everything for you: codegolf.meta.stackexchange.com/a/4764/10740 – Timtech May 11 '17 at 18:12

# Perl 5.10, 21 bytes

{$^T+50<time?do:redo} Outputs "Null filename used at -e line 1." after [50,51) seconds. Or 22 bytes for Perl 5.22: {$^T+50<time?die:redo}
• Welcome to PPCG! It's easier for people to understand your byte count if you just present it as {^T+50<time?do:redo} (most people will know how to invoke it or those who don't know probably also don't need to know). – Martin Ender May 7 '17 at 20:50 • Does this require any specific Perl version? The 5.22.2 I have displays “syntax error at -e line 1, near "do:"” immediately. – manatwork May 8 '17 at 15:50 • @manatwork I verified that you are correct and that it works with perl 5.10. – gogators May 8 '17 at 20:29 • as stderr is ignored by default, could you change it to output to stdout? – Felipe Nardi Batista May 10 '17 at 13:19 • Explicitly, it say "STDERR can be ignored completely, as long as STDOUT has the required output". Which means the same as "STDERR may be considered if STDOUT does not have the required output". In this case STDOUT does not have the required output, so STDERR need not be ignored. – gogators May 19 '17 at 21:19 # Python 2, 57 54 bytes -3 bytes thanks to Felipe Nardi Batista. from time import* b=time()+50 while time()<b:0 print 1 Try it online! ## Another solution, 48 bytes This answer will only work if printing to STDERR is allowed. This will end in a NameError, printing much more than one character. from time import* b=time()+50 while time()<b:0 a # APL (Dyalog), 21 bytes -1 thanks to marinus. {3⊃⍵≥⎕AI:∇⍵⋄1}5e4+⎕AI ⎕AIAccount Information (UserID, ComputeTime, ConnectTime, KeyingTime) 5E4+ add 50000 (milliseconds) { apply the following anonymous function where the argument is represented by [if the] 3⊃ third item (truth value, i.e that of ConnectTime) of ⍵≥⎕AI is greater than or equal to Account Information : then ∇⍵ recurse this function on the unmodified argument else 1 return one } [end of anonymous function] Try it online! Debug says Real time: 50.039 s, or disable output cache for real-time effect. • With a d-fn it's one shorter: {3⌷⍵≥⎕AI:∇⍵⋄1}5e4+⎕AI – marinus May 8 '17 at 21:02 • @marinus Thanks. – Adám May 9 '17 at 5:56 ## C, 4544 43 bytes i;f(){for(time(&i);time(0)-i<50;);puts(f);} See it work here. • is it guaranteed that the puts(f) will always have at least 1 visible character? – Felipe Nardi Batista May 9 '17 at 10:49 • @FelipeNardiBatista It will on the implementation I choose (See the link). Otherwise It is necessary to check that the function f isn't aligned to or more than 0xFF bytes. This can be manipulated using compiler flags. – 2501 May 9 '17 at 10:53 ## Bash, 26 bytes f()(((SECONDS<50))&&f);f;. Partially ungolfed: f () ( ((SECONDS < 50)) && f ) f . SECONDS is a magic variable that counts the number of seconds since the shell started. I define a function that recurses until the value is below the threshold. Once the wait is over, run the builtin . which prints an error message because it's missing an argument. Beware that since the function's body is in parentheses, bash forks a new process for each recursive invocation, which may consume a lot of entries in your process table. A loop would keep resource usage down, but it's longer. for((;SECONDS<50;));do :;done;. If you want to have output on standard output rather than to the screen and you're running a sufficiently Unix-like system with at least one user logged in, you can replace the final . by w. If you want to stick to pure bash then I can't think of a way to produce output in less than 28 bytes. f()(((SECONDS<50))&&f);f;pwd • as stderr is ignored by default, could you change it to output to stdout? – Felipe Nardi Batista May 10 '17 at 10:52 • @FelipeNardiBatista At the time I posted, the requirement was to output to the screen, not to standard output. – Gilles May 10 '17 at 20:08 • yes, but as the default is ignoring stderr, your answer would not output anything – Felipe Nardi Batista May 10 '17 at 20:43 # Pyth, 9 bytes W>50.d1;G Try it here. # PHP, 42 36 bytes for(t=time();time()-$t<50;);echo 1; • -6 bytes, thanks to @Titus How to run > php -r <code> • Use -r to avoid the PHP tag. – Titus May 8 '17 at 9:59 • @Titus note taken, thx. – Khaled.K May 8 '17 at 10:22 # Javascript, 4339373534 33 bytes for(t=+new Date;new Date<t+5e4;)1 Outputs 1 after 50 seconds. Open console and run snippet. The snippet only runs for 5 seconds, so your page won't stall for too long :) for(t=+new Date;new Date<t+5e3;)1 Saved 10(!) bytes thanks to @CraigAyre: • 43 : t=+new Date();while(+new Date()<t+50000)0;x • 39 : t=+new Date;while(+new Date<t+50000)0;x • 37 : t=+new Date;while(+new Date<t+5e4)0;x • 35 : t=+new Date;while(new Date<t+5e4);x • 34 : t=+new Date;while(new Date<t+5e4)1 • 33 : for(t=+new Date;new Date<t+5e4;)1 • – Craig Ayre May 7 '17 at 18:14 • in the console it does outputs 1, but not in the snippet, it just freezes my browser for 5 secs. isn't that a JS REPL answer? – Felipe Nardi Batista May 8 '17 at 14:45 • @FelipeNardiBatista I don't know what a JS REPL answer is, but you're right. The previous version of my snippet did output when run. Is it a requirement that it should function when ran as a snippet? – Thomas W May 8 '17 at 15:29 # 05AB1E, 16 14 bytes žc50+60%[DžcQ# Try it online! I'm new to 05AB1E, so any golfing tips would be appreciated. Explanation: žc50+60%[DžcQ# žc Push current amount of seconds. 50+ Add 50. 60% Modulo 60. [ Infinite loop. D Duplicate top of stack žc Push current seconds. Q# If current seconds, and start time+50 are the same, break. Implicit print. The basic idea of this program is to get what the time will be in 50 secs and loop until the current time is equal. So to get the time in 50 seconds, it gets the current time and adds 50. Then, since 05AB1E's clock returns the time since the last minute change, it needs to modulo 60, to get back in the correct range. Then the program loops until the second amount is the same as the desired. ## Ruby, 36 33 35 bytes t=Time.now;1until Time.now-t>50;p 1 Ruby handily supports subtraction of Time objects, returning the difference in seconds. Prints the character 1 (being Ruby's internal representation of the entity 1) when done. Edit: saved 2 bytes by changing to an error message, 1 byte thanks to G B Edit: re-added 2 bytes (stderr doesn't count) • I can shave two characters (the  1 from the end) if throwing an error counts as displaying output :) – Chowlett May 8 '17 at 15:35 • You could use 1while instead of {}while to save another character. – G B May 9 '17 at 12:20 • as stderr is ignored by default, could you change it to output to stdout? – Felipe Nardi Batista May 10 '17 at 10:53 • Shame. That's two bytes longer. – Chowlett May 10 '17 at 17:31 # Processing, 47 bytes void draw(){if(millis()>5e4){print(X);exit();}} After 50 seconds, the program prints 0 and exits. • What language is that? – 2501 May 7 '17 at 17:08 • @2501 It's Processing: processing.org – Cows quack May 7 '17 at 17:08 • What is X, where is it being defined? – Pavel May 7 '17 at 18:43 • @Phoenix It is one of Processing's constants, PI is an example. They do not have to be initialised. You can see the implementation of X here: github.com/processing/processing/blob/master/core/src/… – Cows quack May 7 '17 at 19:03 # PowerShell, 38 for($d=(date)+[int]5e8;(date)-lt$d){}1 Very trivial; will just wait until the time is 50 seconds later and then prints 1. # Java, 116114109 105 bytes • -2 bytes, thanks to @jaxad0127 • -4 bytes, thanks to @KevinCruijssen Try Online double t(){return System.nanoTime();} void w(){for(double s=t();t()-s<5e+10;);System.out.print("\0007!");} Note on unix, this should ring a beep. • You can save some bytes by using 5e4 instead of 50000. – jaxad0127 May 7 '17 at 19:26 • @jaxad0127 done, thanx for the tip – Khaled.K May 8 '17 at 6:58 • You can save a byte by changing the while to a for and put s inside it: for(long s=t();t()-s<5e4;); Also, I count 109 bytes in your current answer instead of 108 (after removing the newline). With the while to for loop change it becomes 108 however. Also, why use System.currentTimeMillis() when System.nanoTime() is shorter? – Kevin Cruijssen May 8 '17 at 9:40 • @KevinCruijssen yes, change considered now. – Khaled.K May 8 '17 at 10:18 • you don't need the \a (\0007), you'll just lose some bytes – Felipe Nardi Batista May 8 '17 at 10:42 # x86 16 bit machine code on MS-DOS - 21 bytes 00000000 53 1f a1 6c 04 05 8e 03 3b 06 6c 04 77 fa b2 6e |S..l....;.l.w..n| 00000010 b4 02 cd 21 c3 |...!.| 00000015 Commented assembly: org 100h section .text start: push bx ; notice: bx starts as 0 pop ds ; set the data segment to 0; this allows us to ; read the tick count without segment selectors mov ax,word [046ch] ; read the low 16 bit of the tick count add ax,910 ; 910 ticks = 49.98 seconds ; here we used ax because the encoding for both ; the mov and the add is one byte shorter lop: cmp ax,word [046ch] ; compare the stop time with the current time ja lop ; loop if still above mov dl,'n' ; n is for noodles mov ah,2 int 21h ; print ret ; quit This could be shaved down to 16 bytes by replacing the final three instructions with int 18h, which on ancient machines would invoke the ROM built-in BASIC interpreter and almost everywhere else prints something like "No ROM BASIC" and reboot after a key press, but after discussing this with OP it was decided that this wouldn't be allowed. ### Interrupt + self-modifying code approach - 23 bytes This is another approach; it turns out to be bigger, but I post it anyway because it is way more fun. 00000000 b8 1c 25 ba 12 01 cd 21 b9 8e 03 e2 fb b4 02 cd |..%....!........| 00000010 21 c3 ff 0e 09 01 cf |!......| 00000017 org 100h section .text %define counter lop+1 ; see below start: ; setup interrupt handler mov ax,251ch ; function 25h (replace interrupt vector) ; interrupt 1ch (user timer) mov dx,interrupt_handler ; timer ISR int 21h lop: mov cx,910 ; the 910 immediate value is actually pointed by counter, ; which is decremented in interrupt_handler loop lop ; decrement and loop as long as cx is nonzero (the decrement is ; not relevant, we are always resetting cx at each iteration) mov ah,2 ; function 2 (print character); dl is already a printable character int 21h ret ; quit interrupt_handler: dec word[counter] ; at every tick decrement the counter iret # PHP, 43 bytes I think when you´re sleepy, your ears are more alert than your eyes, so: for($t=time();;)echo chr(time()-$t<50?9:7); prints horizontal tabs in the first 50 seconds, BEL codes after that. Run with -r. • I haven't thought about printing (non visible) characters before the time limit, nice. – Felipe Nardi Batista May 8 '17 at 10:44 • Is the Elvis operator a thing in PHP? ?:, could save a byte by printing the time()-$t implicitly instead of tabs? – Magic Octopus Urn May 8 '17 at 15:01
• @carusocomputing Elvis would print the difference or the else branch; i.e. some ASCII between 0 and 49; but there shouldn´t be any printable in the first 50 seconds -> not applicable here. – Titus May 8 '17 at 16:52
• Then why is printing tabs acceptable? – Magic Octopus Urn May 8 '17 at 18:03
• @carusocomputing Whitespace characters (newline, space, tab, ...) are not considered visible characters for this challenge. – Titus May 9 '17 at 6:18

# C# - 100 bytes

using System;
while(DateTime.Now<t);
Console.Write(t);
}
• Welcome to PPCG! It looks like there is some white space left which can be removed, e.g. var t=DateTime .... – Laikoni May 7 '17 at 18:49
• Not sure where you're getting 79 bytes from, because your code in it's current state is 92 bytes. Even golfed to remove all whitespace it's still 83 bytes – Skidsdev May 8 '17 at 8:40
• This is 96 bytes if you remove the new lines. – TheLethalCoder May 8 '17 at 15:30

## R, 41 bytes

s=Sys.time;x=s();while(s()-x<50){};cat(1)
• cat(1) saves 2 bytes – Felipe Nardi Batista May 8 '17 at 14:05
• @FelipeNardiBatista Good idea, thanks. – Sven Hohenstein May 8 '17 at 15:54

# Bash, 68 43 bytes

for((e=date +%s+50;date +%s<e;)){ :;};w

Lists logged in users after 50 seconds.

Edit: Thanks a lot, manatwork! -25 bytes.

Try it online!

• As I count, would be shorter without variable $t. And avoid expr, Bash can do integer arithmetic itself. And better list the logged in users with w – not just shorter but produces output on TIO too. for((e=date +%s+50;date +%s<e;)){ :;};w – manatwork May 8 '17 at 16:05 • I had no idea that there is a way to do arithmetic without expr command. From what I read so far, it only works if it's done inside ((...)). Thanks for your help! – Max Lawnboy May 8 '17 at 17:33 C#, 73 bytes var n=DateTime.Now.AddSeconds(50);while(DateTime.Now<n);Console.Write(n); • Hi, you can shave of 8 bytes of this if you change Console.Write(n) to n.Dump(). .Dump() is a LinQPad specific method not a C# one if I'm not mistaken, so I don't know if that is allowed by the rules. (If it is, it saves 8 bytes) – Bojan B May 9 '17 at 6:34 # Aceto, 16 bytes 6+_p *-iX 59 Tt< Sets a Timer, reads the timer difference and pushes it on the stack. Pushes 9 and 5, multipl*es them, pushes 6, +dds them. We now have a 51 on the stack (on top of the initially small-ish timer number). We substr-ct them from each other, getting initially something a little bit bigger than 51. We cast it to an integer, and mirror (_) if the integer is truthy (i.e. not 0). In that case, we go to the left (<) and check our timer again, going into a loop. Otherwise, we print 0 from the empty stack, and eXit. After 50 seconds, the timer will be 50+ε for some small ε, meaning our subtraction yields 50+ε-51 = -ε, since ε is smaller than 1 the corresponding integer will be 0. ## C, 4143 39 Bytes a;b(c){time(c?0:&a)-a>50?puts(b):b(1);} Try it online • as a function, i can call it as f("") and it won't print anything. you could use 2501's trick to even cut out 1 byte – Felipe Nardi Batista May 9 '17 at 11:11 • Great!. It is still better than mine. – 2501 May 9 '17 at 15:33 • Damn.. I'm out of ideas – Johan du Toit May 9 '17 at 16:48 • @2501, <s>I'm out of ideas</s> ;-) – Johan du Toit May 10 '17 at 7:04 • That is invalid in my opinion, because the function requires an argument. This is similar to having information stored in globals, but isn't counted in the byte score count. (Or resetting globals in between function calls, which is what the argument is doing basically.) – 2501 May 10 '17 at 7:21 ## REXX, 33 bytes do while time(e)<50 nop end say a ## C#, 91 77 bytes n=()=>System.DateTime.Now;_=>{var t=n();while((n()-t).Seconds<50);return t;}; # T-SQL, 62 bytes DECLARE @ DATETIME=GETDATE()WHILE DATEDIFF(S,@,GETDATE())<50_: After the execution in SSMS, this will print the message "Command(s) completed successfully." plus a bell sound [bonus :)]. # AWK, 48 bytes BEGIN{for($0=systime();systime()-\$0<50;)1;print}

Try it online!

This assumes that input is not allowed.

# Swift - 41 bytes

Just outgolfing @Samira's answer, improving it drastically

var d=Date()+50;while Date()<d{};print(d)

Prints the date it started running to wake one up, e.g: if it's ran at 12:38 UTC, it outputs 2017-05-12 12:38:51 +0000 after 50 seconds.