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\$
    – sporkl
    May 7, 2017 at 14:49
  • \$\begingroup\$ @ComradeSparklePony if it always outputs at least 1 visible character, sure \$\endgroup\$ May 7, 2017 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, 2017 at 15:35
  • 4
    \$\begingroup\$ Is it ok to reboot the machine after printing the "visible characters"? \$\endgroup\$ May 7, 2017 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\$ May 8, 2017 at 14:33

36 Answers 36


Swift , 108 bytes

 var a=Date().addingTimeInterval(59.0);while(Date().timeIntervalSinceNow<a.timeIntervalSinceNow){};print("W")
  • \$\begingroup\$ Please add comment before doing a downvote. \$\endgroup\$
    – Samaira
    May 8, 2017 at 9:37
  • \$\begingroup\$ Welcome to PPCG! The goal of code-golf challenges is to use as few bytes as possible and the challenge allows to output only a single character as wake-up signal, so you don't need "WakeUp" as a string, just for example "W" would suffice. \$\endgroup\$
    – Laikoni
    May 8, 2017 at 9:38
  • \$\begingroup\$ Also can the spaces at the beginning be omitted? var a=Date(). \$\endgroup\$
    – Laikoni
    May 8, 2017 at 9:39
  • \$\begingroup\$ Agreed the space can be omitted also its written a tleast one character to wakeup that I didn't read. But there is no wrong logic used in this code. Neither a timer nor a sleep command. \$\endgroup\$
    – Samaira
    May 8, 2017 at 9:42
  • \$\begingroup\$ This solution is terribly inefficient. The purpose here is to shorten the code as much as possible. This answer is an outgolfing of this one. \$\endgroup\$
    – Mr. Xcoder
    May 12, 2017 at 12:44

VBA, 98 Bytes

Not sure if allowed...but here! It waits a single second, but doesn't wait the whole time. Still working on the language!

Sub Tm()
For i = 0 To 50
    If i = 50 Then
        MsgBox "!"
    Application.Wait (Now + TimeValue("0:00:01"))
    End If
Next i
End Sub
  • \$\begingroup\$ @Ben, by using Application.Wait(Now + TimeValue ("0:00:50"), it invalidates the entire code, as it cannot just wait 50 seconds. It specifically says in the challenge to check every second to determine when to ring. \$\endgroup\$
    – Anoplexian
    May 9, 2017 at 14:03
  • \$\begingroup\$ that's not exactly right, you're not checking for the elapsed time, you're calling 50x the function that it is not allowed \$\endgroup\$ May 10, 2017 at 11:00

JS (ES6), 64 bytes


C#, 72 bytes

for(var x=DateTime.Now;DateTime.Now<x.AddSeconds(50););Console.Write(0);

Windows Batch, 123 121 126 122 112 111 107 100 95 bytes

@if %e% geq 60 @set/ae-=60
@if %e% neq %TIME:~6,2% @goto w


@set /a e=1%Time:~6,2%+50-100               ::Calcuate the result time
@if %e% geq 60 @set/ae-=60                  ::If result time > 59, set it to correct time 

:w                                          :: Marker of the wait loop
@if %e% equ %TIME:~6,2% (cd)else (@goto w)  ::Returns current dir when program ended
                                            :: Or Else go back to wait for loop
  • \$\begingroup\$ you need to output to stdout \$\endgroup\$ May 10, 2017 at 10:39
  • 1
    \$\begingroup\$ You didn't specific this in the rules.... \$\endgroup\$
    – stevefestl
    May 10, 2017 at 10:40
  • \$\begingroup\$ read comments in the post \$\endgroup\$ May 10, 2017 at 10:41
  • \$\begingroup\$ Well then why wouldn't you tell the Python2 answerer, Bash answerer, Ruby answerer but ME \$\endgroup\$
    – stevefestl
    May 10, 2017 at 10:42
  • \$\begingroup\$ python2's is an alternative, the original is stdout, i haven't read all of them yet, i'm reading the new ones as they come. chill \$\endgroup\$ May 10, 2017 at 10:44

This may be foul play.

Bash, 24 Bytes

ping -rqc50|wc

To verify +6 bytes

ping -rqc50|tail -n2 is IPv4 dummy address. It send packet for 50 times in one second interval because it would not be reached.

  • \$\begingroup\$ That's includes in functions that wait for time. And woundn't that print stuff like unreachable dest? \$\endgroup\$ May 9, 2017 at 15:33
  • \$\begingroup\$ As expected after all -- this is kind of wait. It dose not print any characters while it is sending 50 packets. wc is WordCount. It is not return until end of stream. In some environments, it shows help because ping -r option is not supported. (ex. s-macke.github.io/jor1k/demos/main.html Try:ping -qc50|wc) \$\endgroup\$
    – okud
    May 9, 2017 at 17:09

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