[Question]
  [
**This question already has answers here**:
 
 
[Stop, stand there where you are!](/questions/55293/stop-stand-there-where-you-are)
 (29 answers)
 
Closed 6 years ago.
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 [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest code wins.
  
[Answer]
# 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)](https://tio.run/##y08uSSxL/f@/JDPZOiWfqzSvJDNHoSQ/2c7U2vD/fwA) or paste it into [**Octave Online**](http://octave-online.net/).
[Answer]
# [MATL](https://github.com/lmendo/MATL), 7 bytes
```
1`Z`50<
```
[Try it online!](https://tio.run/nexus/matl#@2@YEJVgaGDz///XvHzd5MTkjFQA "MATL – TIO Nexus") The linked code uses `10` instead of `50`.
### 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)
```
[Answer]
# [Lua](https://www.lua.org), 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!](https://tio.run/nexus/lua#@1@ekZmTqpBfrJeck5@craFpY2qgkJKvkJqXYl1QlJlXoq6o/v8/AA "Lua – TIO Nexus")
[Answer]
# 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.
[Answer]
# **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}
```
[Answer]
# [Python 2](https://docs.python.org/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!](https://tio.run/nexus/python2#@59WlJ@rUJKZm6qQmVuQX1SixZVkC@JqaGqbGnCVZ2TmpCpA@DZJVgZcBUWZeSUKhv//f83L101OTM5IBQA "Python 2 – TIO Nexus")
## 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
```
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 21 bytes
-1 thanks to [marinus](https://codegolf.stackexchange.com/users/1426/marinus).
```
{3⊃⍵≥⎕AI:∇⍵⋄1}5e4+⎕AI
```
`⎕AI` **A**ccount **I**nformation (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 **A**ccount **I**nformation
 `:` then
  `∇⍵` recurse this function on the unmodified argument
 `⋄` else
  `1` return one
`}` [end of anonymous function]
[Try it online!](https://tio.run/nexus/apl-dyalog#e9TRHpSZl@6b@r/a@FFX86PerY86lz7qm@roafWoox3E7W4xrDVNNdEGC/4HCv6HaAAA "APL (Dyalog Unicode) – TIO Nexus") *Debug* says *Real time: 50.039 s*, or *disable output cache* for real-time effect.
[Answer]
## C, ~~45~~ ~~44~~ 43 bytes
```
i;f(){for(time(&i);time(0)-i<50;);puts(f);}
```
See it [work here](https://tio.run/nexus/c-gcc#@59pnaahWZ2WX6RRkpmbqqGWqWkNZhho6mbamBpYa1oXlJYUa6RpWtf@z8wrUchNzMzTUCjLz0xR0OSq5uIE6law5qr9DwA).
[Answer]
## Bash, 26 bytes
```
f()(((SECONDS<50))&&f);f;.
```
Partially ungolfed:
```
f () (
  ((SECONDS < 50)) && f
)
f
.
```
[`SECONDS`](https://www.gnu.org/software/bash/manual/bash.html#index-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
```
[Answer]
# Pyth, 9 bytes
```
W>50.d1;G
```
[Try it here.](http://pyth.herokuapp.com/?code=W%3E50.d1;G)
[Answer]
# PHP, ~~42~~ 36 bytes
```
for($t=time();time()-$t<50;);echo 1;
```
* -6 bytes, thanks to @Titus
**How to run**
```
> php -r <code>
```
[Answer]
# 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`
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~16~~ 14 bytes
```
žc50+60%[DžcQ#
```
[Try it online!](https://tio.run/nexus/05ab1e#@390X7KpgbaZgWq0C5AZqPz//9e8fN3kxOSMVAA)
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.
[Answer]
# Processing, 47 bytes
```
void draw(){if(millis()>5e4){print(X);exit();}}
```
After 50 seconds, the program prints `0` and exits.
[Answer]
# 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`. 
[Answer]
# Java, ~~116~~ ~~114~~ ~~109~~ 105 bytes
* -2 bytes, thanks to @jaxad0127
* -4 bytes, thanks to @KevinCruijssen
[**Try Online**](https://tio.run/nexus/java-openjdk#dY0xC8IwFIRn@ysyJqDFxSm6uzjVTRxiDfWRNCl5LxYJ@e0xFSfBW46Du@9K6a1CZMcmNasp3iz0DElRNevdwIiLFDTF4Fj3QtJj28cQtKMzjPoE1gJyIfPv9unhzua6/UDwUDFrI@cHWM25WeIGxX63rRLyC/aR2imAI27@EUcFjndUS8PlqsKAIi0vkuUmlzc)
```
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.
[Answer]
# 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`](https://en.wikipedia.org/wiki/BIOS_interrupt_call#INT_18h:_execute_BASIC), 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
```
[Answer]
# 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`.
[Answer]
# C# - 100 bytes
```
using System;
void q(){var t=DateTime.Now.AddSeconds(50);
while(DateTime.Now<t);
Console.Write(t);
}
```
[Answer]
## R, 41 bytes
```
s=Sys.time;x=s();while(s()-x<50){};cat(1)
```
[Answer]
# [Bash](https://www.gnu.org/software/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!](https://tio.run/nexus/bash#@5@WX6ShkWqbkJJYkqqgrVqcoG1qYI3g2aRaa2pWK1hZ11qX//8PAA "Bash – TIO Nexus")
[Answer]
**C#, 73 bytes**
`var n=DateTime.Now.AddSeconds(50);while(DateTime.Now<n);Console.Write(n);`
[Answer]
# [Aceto](https://github.com/L3viathan/Aceto), 16 bytes
```
6+_p
*-iX
59
Tt<
```
Sets a `T`imer, reads the `t`imer 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 `i`nteger, 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 `p`rint 0 from the empty stack, and e`X`it.
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.
[Answer]
## C, ~~41~~ ~~43~~ 39 Bytes
```
a;b(c){time(c?0:&a)-a>50?puts(b):b(1);}
```
[Try it online](https://tio.run/nexus/c-gcc#@59onaSRrFldkpmbqpFsb2Cllqipm2hnamBfUFpSrJGkaZWkYahpXfs/NzEzT0OTq5qLM0nDQNOaq/b/v@S0nMT04v@6/kZf8/J1kxOTM1IB)
[Answer]
## 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)
[Answer]
## REXX, 33 bytes
```
do while time(e)<50
  nop
  end
say a
```
[Answer]
## C#, ~~91~~ 77 bytes
```
n=()=>System.DateTime.Now;_=>{var t=n();while((n()-t).Seconds<50);return t;};
```
[Answer]
# 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 :)].
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), 48 bytes
```
BEGIN{for($0=systime();systime()-$0<50;)1;print}
```
[Try it online!](https://tio.run/nexus/awk#@@/k6u7pV52WX6ShYmBbXFlckpmbqqFpDWfpqhjYmBpYaxpaFxRl5pXU/v8PAA "AWK – TIO Nexus")
This assumes that input is not allowed. 
[Answer]
# 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.
]