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?


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.


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

36 Answers 36


MATL, 7 bytes


Try it online! The linked code uses 10 instead of 50.


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)
  • \$\begingroup\$ I think this code is pretty self-explanatory. \$\endgroup\$ – Erik the Outgolfer May 7 '17 at 14:56
  • 1
    \$\begingroup\$ @Erik And very similar to Stewie's answer. Anyway I'll add an explanation later \$\endgroup\$ – Luis Mendo May 7 '17 at 15:04

Octave, 22 21 bytes

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

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.

  • \$\begingroup\$ Does this also work in Octave online? \$\endgroup\$ – Michthan May 8 '17 at 10:06
  • 2
    \$\begingroup\$ @Michthan yes. Links added to TIO and Octave Online. I recommend choosing a lower time than 50 seconds when testing it :) \$\endgroup\$ – 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!

  • \$\begingroup\$ I don't know Lua, but can't you print a number and save 2 bytes? \$\endgroup\$ – totallyhuman May 8 '17 at 20:41
  • \$\begingroup\$ 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) \$\endgroup\$ – Finn O'leary May 8 '17 at 20:58

TI-Basic, 14 12 bytes

While 50>checkTmr(Ans

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

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

Perl 5.10, 21 bytes


Outputs "Null filename used at -e line 1." after [50,51) seconds.

Or 22 bytes for Perl 5.22:

  • 1
    \$\begingroup\$ 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). \$\endgroup\$ – Martin Ender May 7 '17 at 20:50
  • \$\begingroup\$ Does this require any specific Perl version? The 5.22.2 I have displays “syntax error at -e line 1, near "do:"” immediately. \$\endgroup\$ – manatwork May 8 '17 at 15:50
  • \$\begingroup\$ @manatwork I verified that you are correct and that it works with perl 5.10. \$\endgroup\$ – gogators May 8 '17 at 20:29
  • \$\begingroup\$ as stderr is ignored by default, could you change it to output to stdout? \$\endgroup\$ – Felipe Nardi Batista May 10 '17 at 13:19
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – gogators May 19 '17 at 21:19

Python 2, 57 54 bytes

-3 bytes thanks to Felipe Nardi Batista.

from time import*
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*
while time()<b:0

APL (Dyalog), 21 bytes

-1 thanks to marinus.


⎕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


  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.

  • \$\begingroup\$ With a d-fn it's one shorter: {3⌷⍵≥⎕AI:∇⍵⋄1}5e4+⎕AI \$\endgroup\$ – marinus May 8 '17 at 21:02
  • \$\begingroup\$ @marinus Thanks. \$\endgroup\$ – Adám May 9 '17 at 5:56

C, 45 44 43 bytes


See it work here.

  • \$\begingroup\$ is it guaranteed that the puts(f) will always have at least 1 visible character? \$\endgroup\$ – Felipe Nardi Batista May 9 '17 at 10:49
  • \$\begingroup\$ @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. \$\endgroup\$ – 2501 May 9 '17 at 10:53

Bash, 26 bytes


Partially ungolfed:

f () (
  ((SECONDS < 50)) && 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.

  • \$\begingroup\$ as stderr is ignored by default, could you change it to output to stdout? \$\endgroup\$ – Felipe Nardi Batista May 10 '17 at 10:52
  • 1
    \$\begingroup\$ @FelipeNardiBatista At the time I posted, the requirement was to output to the screen, not to standard output. \$\endgroup\$ – Gilles 'SO- stop being evil' May 10 '17 at 20:08
  • \$\begingroup\$ yes, but as the default is ignoring stderr, your answer would not output anything \$\endgroup\$ – Felipe Nardi Batista May 10 '17 at 20:43

Pyth, 9 bytes


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>
  • \$\begingroup\$ Use -r to avoid the PHP tag. \$\endgroup\$ – Titus May 8 '17 at 9:59
  • \$\begingroup\$ @Titus note taken, thx. \$\endgroup\$ – Khaled.K May 8 '17 at 10:22

Javascript, 43 39 37 35 34 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
  • 1
    \$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$ – Craig Ayre May 7 '17 at 18:14
  • \$\begingroup\$ 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? \$\endgroup\$ – Felipe Nardi Batista May 8 '17 at 14:45
  • \$\begingroup\$ @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? \$\endgroup\$ – Thomas W May 8 '17 at 15:29

05AB1E, 16 14 bytes


Try it online!

I'm new to 05AB1E, so any golfing tips would be appreciated.


ž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)

  • \$\begingroup\$ I can shave two characters (the ` 1` from the end) if throwing an error counts as displaying output :) \$\endgroup\$ – Chowlett May 8 '17 at 15:35
  • \$\begingroup\$ You could use 1while instead of {}while to save another character. \$\endgroup\$ – G B May 9 '17 at 12:20
  • \$\begingroup\$ as stderr is ignored by default, could you change it to output to stdout? \$\endgroup\$ – Felipe Nardi Batista May 10 '17 at 10:53
  • \$\begingroup\$ Shame. That's two bytes longer. \$\endgroup\$ – 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.

  • \$\begingroup\$ What language is that? \$\endgroup\$ – 2501 May 7 '17 at 17:08
  • \$\begingroup\$ @2501 It's Processing: processing.org \$\endgroup\$ – user41805 May 7 '17 at 17:08
  • \$\begingroup\$ What is X, where is it being defined? \$\endgroup\$ – Pavel May 7 '17 at 18:43
  • 1
    \$\begingroup\$ @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/… \$\endgroup\$ – user41805 May 7 '17 at 19:03

PowerShell, 38


Very trivial; will just wait until the time is 50 seconds later and then prints 1.


Java, 116 114 109 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.

  • \$\begingroup\$ You can save some bytes by using 5e4 instead of 50000. \$\endgroup\$ – jaxad0127 May 7 '17 at 19:26
  • \$\begingroup\$ @jaxad0127 done, thanx for the tip \$\endgroup\$ – Khaled.K May 8 '17 at 6:58
  • \$\begingroup\$ 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? \$\endgroup\$ – Kevin Cruijssen May 8 '17 at 9:40
  • \$\begingroup\$ @KevinCruijssen yes, change considered now. \$\endgroup\$ – Khaled.K May 8 '17 at 10:18
  • \$\begingroup\$ you don't need the \a (\0007), you'll just lose some bytes \$\endgroup\$ – 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                                    |...!.|

Commented assembly:

    org 100h

section .text

    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
    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                              |!......|


    org 100h

section .text

%define counter lop+1   ; see below
    ; setup interrupt handler
    mov ax,251ch                ; function 25h (replace interrupt vector)
                                ; interrupt 1ch (user timer)
    mov dx,interrupt_handler    ; timer ISR
    int 21h
    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

    dec word[counter]   ; at every tick decrement the counter

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.

  • \$\begingroup\$ I haven't thought about printing (non visible) characters before the time limit, nice. \$\endgroup\$ – Felipe Nardi Batista May 8 '17 at 10:44
  • \$\begingroup\$ Is the Elvis operator a thing in PHP? ?:, could save a byte by printing the time()-$t implicitly instead of tabs? \$\endgroup\$ – Magic Octopus Urn May 8 '17 at 15:01
  • \$\begingroup\$ @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. \$\endgroup\$ – Titus May 8 '17 at 16:52
  • \$\begingroup\$ Then why is printing tabs acceptable? \$\endgroup\$ – Magic Octopus Urn May 8 '17 at 18:03
  • \$\begingroup\$ @carusocomputing Whitespace characters (newline, space, tab, ...) are not considered visible characters for this challenge. \$\endgroup\$ – Titus May 9 '17 at 6:18

C# - 100 bytes

using System;
void q(){var t=DateTime.Now.AddSeconds(50);
  • \$\begingroup\$ Welcome to PPCG! It looks like there is some white space left which can be removed, e.g. var t=DateTime .... \$\endgroup\$ – Laikoni May 7 '17 at 18:49
  • \$\begingroup\$ 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 \$\endgroup\$ – Skidsdev May 8 '17 at 8:40
  • \$\begingroup\$ This is 96 bytes if you remove the new lines. \$\endgroup\$ – TheLethalCoder May 8 '17 at 15:30

R, 41 bytes

  • 1
    \$\begingroup\$ cat(1) saves 2 bytes \$\endgroup\$ – Felipe Nardi Batista May 8 '17 at 14:05
  • \$\begingroup\$ @FelipeNardiBatista Good idea, thanks. \$\endgroup\$ – 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!

  • \$\begingroup\$ 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 \$\endgroup\$ – manatwork May 8 '17 at 16:05
  • \$\begingroup\$ 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! \$\endgroup\$ – Maxim Mikhaylov May 8 '17 at 17:33

C#, 73 bytes

var n=DateTime.Now.AddSeconds(50);while(DateTime.Now<n);Console.Write(n);

  • \$\begingroup\$ 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) \$\endgroup\$ – Bojan B May 9 '17 at 6:34

Aceto, 16 bytes


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, 41 43 39 Bytes


Try it online

  • \$\begingroup\$ 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 \$\endgroup\$ – Felipe Nardi Batista May 9 '17 at 11:11
  • \$\begingroup\$ Great!. It is still better than mine. \$\endgroup\$ – 2501 May 9 '17 at 15:33
  • \$\begingroup\$ Damn.. I'm out of ideas \$\endgroup\$ – Johan du Toit May 9 '17 at 16:48
  • \$\begingroup\$ @2501, <s>I'm out of ideas</s> ;-) \$\endgroup\$ – Johan du Toit May 10 '17 at 7:04
  • \$\begingroup\$ 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.) \$\endgroup\$ – 2501 May 10 '17 at 7:21

REXX, 33 bytes

do while time(e)<50
say a

C#, 91 77 bytes

n=()=>System.DateTime.Now;_=>{var t=n();while((n()-t).Seconds<50);return t;};

T-SQL, 62 bytes


After the execution in SSMS, this will print the message "Command(s) completed successfully." plus a bell sound [bonus :)].


AWK, 48 bytes


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.


Not the answer you're looking for? Browse other questions tagged or ask your own question.