Ring me when our cup noodles are ready

25

3

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.

Felipe Nardi Batista

Posted 2017-05-07T14:33:52.477

Reputation: 2 345

Question was closed 2017-05-20T10:33:10.177

Can the output be non-deterministic (something different every time)? – Comrade SparklePony – 2017-05-07T14:49:07.470

@ComradeSparklePony if it always outputs at least 1 visible character, sure – Felipe Nardi Batista – 2017-05-07T14:50:51.507

26The problem with this approach is the risk that the CPU fan will wake you up early... – Neil – 2017-05-07T15:35:50.710

4Is it ok to reboot the machine after printing the "visible characters"? – Matteo Italia – 2017-05-07T16:24:37.987

@MatteoItalia would the SO print the characters or your program? – Felipe Nardi Batista – 2017-05-07T16:26:54.653

@FelipeNardiBatista: difficult to say, it's always the OS that prints the characters in response to an interrupt. – Matteo Italia – 2017-05-07T16:28:18.740

@MatteoItalia if you try to shutdown the computer, your program will close, and the SO will print it's log msgs (unix i mean). so that would not be your program that is printing. what do you have in mind? – Felipe Nardi Batista – 2017-05-07T16:29:59.560

@FelipeNardiBatista: with int 21h/ah=2 I tell DOS what character and it'll print it, with int 18h it prints some stuff and then (usually) reboots. – Matteo Italia – 2017-05-07T16:31:10.683

@MatteoItalia i'll say you can't reboot your computer, if i'd allow that, shutdown 50 in linux would be a valid answer – Felipe Nardi Batista – 2017-05-07T16:34:29.263

@FelipeNardiBatista: jeez, that would actually be a great answer. :-( – Matteo Italia – 2017-05-07T16:36:47.733

Can we return a value from a method or do we have to print to screen or similar? – TheLethalCoder – 2017-05-08T14:32:54.197

1@TheLethalCoder it can be a value returned by a method, but when printed must have at least 1 visible character – Felipe Nardi Batista – 2017-05-08T14:33:53.217

@FelipeNardiBatista Awesome saved 14 bytes from that :) – TheLethalCoder – 2017-05-08T14:40:30.680

Can it be printed to STDERR? – totallyhuman – 2017-05-08T21:15:04.710

@totallyhuman stdout, i'm waiting my cup noodles, not errors ;D – Felipe Nardi Batista – 2017-05-08T21:18:39.503

Is input allowed? – Robert Benson – 2017-05-08T21:22:22.370

@RobertBenson no – Felipe Nardi Batista – 2017-05-10T11:01:44.377

Answers

12

MATL, 7 bytes

1`Z`50<

Try it online! 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)

Luis Mendo

Posted 2017-05-07T14:33:52.477

Reputation: 87 464

I think this code is pretty self-explanatory. – Erik the Outgolfer – 2017-05-07T14:56:07.690

1@Erik And very similar to Stewie's answer. Anyway I'll add an explanation later – Luis Mendo – 2017-05-07T15:04:33.193

19

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.

Stewie Griffin

Posted 2017-05-07T14:33:52.477

Reputation: 43 471

Does this also work in Octave online? – Michthan – 2017-05-08T10:06:10.657

2@Michthan yes. Links added to TIO and Octave Online. I recommend choosing a lower time than 50 seconds when testing it :) – Stewie Griffin – 2017-05-08T10:24:28.033

11

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!

Redouane Red

Posted 2017-05-07T14:33:52.477

Reputation: 311

I don't know Lua, but can't you print a number and save 2 bytes? – totallyhuman – 2017-05-08T20:41:18.840

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 – 2017-05-08T20:58:37.550

8

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.

Timtech

Posted 2017-05-07T14:33:52.477

Reputation: 12 038

I'm new to golfing, so can you explain to me how this is 12 bytes. I count 35. Thx. – gogators – 2017-05-11T18:03:58.120

@gogators Check out this answer I wrote on this subject, it will explain everything for you: https://codegolf.meta.stackexchange.com/a/4764/10740

– Timtech – 2017-05-11T18:12:13.337

7

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}

gogators

Posted 2017-05-07T14:33:52.477

Reputation: 191

1Welcome 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 – 2017-05-07T20:50:54.940

Does this require any specific Perl version? The 5.22.2 I have displays “syntax error at -e line 1, near "do:"” immediately. – manatwork – 2017-05-08T15:50:40.603

@manatwork I verified that you are correct and that it works with perl 5.10. – gogators – 2017-05-08T20:29:55.300

as stderr is ignored by default, could you change it to output to stdout?

– Felipe Nardi Batista – 2017-05-10T13:19:49.177

@FelipeNardiBatista That link says 'STDERR can be ignored completely, as long as STDOUT has the required output' (emphasis mine), it does not specify that stderr is an invalid form of output if stdout is not used to output the required result. – pizzapants184 – 2017-05-19T20:11:10.927

@pizzapants184 does the stdout have the output? no. i didn't say you can't cause erros, i said that everything that goes there is ignored, the output must be in stdout – Felipe Nardi Batista – 2017-05-19T20:12:25.363

@pizzapants184 if all the output is in stdout, you can have anything you want in stderr, that's what it says. but all the output is in stderr, none in stdout – Felipe Nardi Batista – 2017-05-19T20:14:17.480

1Explicitly, 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 – 2017-05-19T21:19:40.200

6

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

totallyhuman

Posted 2017-05-07T14:33:52.477

Reputation: 15 378

5

C, 45 44 43 bytes

i;f(){for(time(&i);time(0)-i<50;);puts(f);}

See it work here.

2501

Posted 2017-05-07T14:33:52.477

Reputation: 748

is it guaranteed that the puts(f) will always have at least 1 visible character? – Felipe Nardi Batista – 2017-05-09T10:49:29.110

@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 – 2017-05-09T10:53:04.960

5

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.

Adám

Posted 2017-05-07T14:33:52.477

Reputation: 37 779

With a d-fn it's one shorter: {3⌷⍵≥⎕AI:∇⍵⋄1}5e4+⎕AI – marinus – 2017-05-08T21:02:12.513

@marinus Thanks. – Adám – 2017-05-09T05:56:23.480

5

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

Gilles 'SO- stop being evil'

Posted 2017-05-07T14:33:52.477

Reputation: 2 531

as stderr is ignored by default, could you change it to output to stdout?

– Felipe Nardi Batista – 2017-05-10T10:52:51.237

1@FelipeNardiBatista At the time I posted, the requirement was to output to the screen, not to standard output. – Gilles 'SO- stop being evil' – 2017-05-10T20:08:39.157

yes, but as the default is ignoring stderr, your answer would not output anything – Felipe Nardi Batista – 2017-05-10T20:43:46.897

3

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.

Comrade SparklePony

Posted 2017-05-07T14:33:52.477

Reputation: 5 784

3

Pyth, 9 bytes

W>50.d1;G

Try it here.

Erik the Outgolfer

Posted 2017-05-07T14:33:52.477

Reputation: 38 134

3

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

Thomas W

Posted 2017-05-07T14:33:52.477

Reputation: 746

1

Let us continue this discussion in chat.

– Craig Ayre – 2017-05-07T18:14:40.603

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 – 2017-05-08T14:45:40.500

@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 – 2017-05-08T15:29:14.817

3

PHP, 42 36 bytes

for($t=time();time()-$t<50;);echo 1;
  • -6 bytes, thanks to @Titus

How to run

> php -r <code>

Khaled.K

Posted 2017-05-07T14:33:52.477

Reputation: 1 435

Use -r to avoid the PHP tag.

– Titus – 2017-05-08T09:59:47.040

@Titus note taken, thx. – Khaled.K – 2017-05-08T10:22:25.663

3

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)

Chowlett

Posted 2017-05-07T14:33:52.477

Reputation: 221

I can shave two characters (the 1 from the end) if throwing an error counts as displaying output :) – Chowlett – 2017-05-08T15:35:14.737

You could use 1while instead of {}while to save another character. – G B – 2017-05-09T12:20:43.373

as stderr is ignored by default, could you change it to output to stdout?

– Felipe Nardi Batista – 2017-05-10T10:53:15.820

Shame. That's two bytes longer. – Chowlett – 2017-05-10T17:31:16.943

2

Processing, 47 bytes

void draw(){if(millis()>5e4){print(X);exit();}}

After 50 seconds, the program prints 0 and exits.

user41805

Posted 2017-05-07T14:33:52.477

Reputation: 16 320

What language is that? – 2501 – 2017-05-07T17:08:00.270

@2501 It's Processing: https://processing.org/

– user41805 – 2017-05-07T17:08:30.440

What is X, where is it being defined? – Pavel – 2017-05-07T18:43:32.167

1

@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: https://github.com/processing/processing/blob/master/core/src/processing/core/PConstants.java#L42

– user41805 – 2017-05-07T19:03:11.540

2

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!

Maxim Mikhaylov

Posted 2017-05-07T14:33:52.477

Reputation: 571

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 – 2017-05-08T16:05:52.970

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! – Maxim Mikhaylov – 2017-05-08T17:33:04.423

2

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.

Khaled.K

Posted 2017-05-07T14:33:52.477

Reputation: 1 435

You can save some bytes by using 5e4 instead of 50000. – jaxad0127 – 2017-05-07T19:26:19.583

@jaxad0127 done, thanx for the tip – Khaled.K – 2017-05-08T06:58:40.163

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 – 2017-05-08T09:40:51.997

@KevinCruijssen yes, change considered now. – Khaled.K – 2017-05-08T10:18:45.960

you don't need the \a (\0007), you'll just lose some bytes – Felipe Nardi Batista – 2017-05-08T10:42:41.207

2

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.

Joey

Posted 2017-05-07T14:33:52.477

Reputation: 12 260

2

C# - 100 bytes

using System;
void q(){var t=DateTime.Now.AddSeconds(50);
while(DateTime.Now<t);
Console.Write(t);
}

John Hathwood

Posted 2017-05-07T14:33:52.477

Reputation: 283

Welcome to PPCG! It looks like there is some white space left which can be removed, e.g. var t=DateTime .... – Laikoni – 2017-05-07T18:49:04.607

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 – 2017-05-08T08:40:28.270

This is 96 bytes if you remove the new lines. – TheLethalCoder – 2017-05-08T15:30:26.543

2

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

Matteo Italia

Posted 2017-05-07T14:33:52.477

Reputation: 3 669

2

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.

Titus

Posted 2017-05-07T14:33:52.477

Reputation: 13 814

I haven't thought about printing (non visible) characters before the time limit, nice. – Felipe Nardi Batista – 2017-05-08T10:44:40.510

Is the Elvis operator a thing in PHP? ?:, could save a byte by printing the time()-$t implicitly instead of tabs? – Magic Octopus Urn – 2017-05-08T15:01:59.513

@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 – 2017-05-08T16:52:35.807

Then why is printing tabs acceptable? – Magic Octopus Urn – 2017-05-08T18:03:50.297

@carusocomputing Whitespace characters (newline, space, tab, ...) are not considered visible characters for this challenge. – Titus – 2017-05-09T06:18:33.083

2

R, 41 bytes

s=Sys.time;x=s();while(s()-x<50){};cat(1)

Sven Hohenstein

Posted 2017-05-07T14:33:52.477

Reputation: 2 464

1cat(1) saves 2 bytes – Felipe Nardi Batista – 2017-05-08T14:05:59.853

@FelipeNardiBatista Good idea, thanks. – Sven Hohenstein – 2017-05-08T15:54:10.173

2

C#, 73 bytes

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

Dazed and Confused

Posted 2017-05-07T14:33:52.477

Reputation: 31

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 – 2017-05-09T06:34:41.997

2

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.

L3viathan

Posted 2017-05-07T14:33:52.477

Reputation: 3 151

2

C, 41 43 39 Bytes

a;b(c){time(c?0:&a)-a>50?puts(b):b(1);}

Try it online

Johan du Toit

Posted 2017-05-07T14:33:52.477

Reputation: 1 524

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 – 2017-05-09T11:11:37.717

Great!. It is still better than mine. – 2501 – 2017-05-09T15:33:35.100

Damn.. I'm out of ideas – Johan du Toit – 2017-05-09T16:48:38.867

@2501, <s>I'm out of ideas</s> ;-) – Johan du Toit – 2017-05-10T07:04:54.583

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 – 2017-05-10T07:21:49.080

1

REXX, 33 bytes

do while time(e)<50
  nop
  end
say a

idrougge

Posted 2017-05-07T14:33:52.477

Reputation: 641

1

C#, 91 77 bytes

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

TheLethalCoder

Posted 2017-05-07T14:33:52.477

Reputation: 6 930

1

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 :)].

WORNG ALL

Posted 2017-05-07T14:33:52.477

Reputation: 61

1

AWK, 48 bytes

BEGIN{for($0=systime();systime()-$0<50;)1;print}

Try it online!

This assumes that input is not allowed.

Robert Benson

Posted 2017-05-07T14:33:52.477

Reputation: 1 339

1

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.

Mr. Xcoder

Posted 2017-05-07T14:33:52.477

Reputation: 39 774

0

Swift , 108 bytes

 var a=Date().addingTimeInterval(59.0);while(Date().timeIntervalSinceNow<a.timeIntervalSinceNow){};print("W")

Samaira

Posted 2017-05-07T14:33:52.477

Reputation: 19

Please add comment before doing a downvote. – Samaira – 2017-05-08T09:37:58.507

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. – Laikoni – 2017-05-08T09:38:05.203

Also can the spaces at the beginning be omitted? var a=Date(). – Laikoni – 2017-05-08T09:39:08.493

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. – Samaira – 2017-05-08T09:42:31.553

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.

– Mr. Xcoder – 2017-05-12T12:44:40.250

@Mr.Xcoder couldn't add comment on your code being new to this Coding Golf. A new thing I got to learn from your code that how we can deal with Date. Everyone has their own logic and I have my own. So may be my code can be bigger than you. But still its better than other languages that are having more bytes than my code. Happy Coding!! – Samaira – 2017-05-12T14:37:01.287

0

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 "!"
    Else
    Application.Wait (Now + TimeValue("0:00:01"))
    End If
Next i
End Sub

Anoplexian - Reinstate Monica

Posted 2017-05-07T14:33:52.477

Reputation: 149

@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. – Anoplexian - Reinstate Monica – 2017-05-09T14:03:25.420

that's not exactly right, you're not checking for the elapsed time, you're calling 50x the function that it is not allowed – Felipe Nardi Batista – 2017-05-10T11:00:42.450

0

JS (ES6), 64 bytes

i=0,r=Date.now();while(1)Math.abs(Date.now()-r-5e4)>50?0:alert()

user68614

Posted 2017-05-07T14:33:52.477

Reputation:

0

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

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

Explanation:

@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

stevefestl

Posted 2017-05-07T14:33:52.477

Reputation: 539

you need to output to stdout – Felipe Nardi Batista – 2017-05-10T10:39:24.897

1You didn't specific this in the rules.... – stevefestl – 2017-05-10T10:40:13.000

read comments in the post – Felipe Nardi Batista – 2017-05-10T10:41:30.883

Well then why wouldn't you tell the Python2 answerer, Bash answerer, Ruby answerer but ME – stevefestl – 2017-05-10T10:42:47.457

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 – Felipe Nardi Batista – 2017-05-10T10:44:17.947

Let us continue this discussion in chat.

– stevefestl – 2017-05-10T10:44:52.777

you can replace echo a with echo – Felipe Nardi Batista – 2017-05-10T11:06:18.387

can't you remove 2>nul ? as stderr is ignored? – Felipe Nardi Batista – 2017-05-10T11:22:49.293

Sometimes the code gives strange error because of octal... – stevefestl – 2017-05-10T11:23:25.903

yes, but errors are ignored by default if stdout has the correct answer – Felipe Nardi Batista – 2017-05-10T11:23:50.773

In batch and cmd, STDOUT and STDERR are all displayed on console – stevefestl – 2017-05-10T11:23:54.443

you can filter it out in your call, so it is ignored in the rules – Felipe Nardi Batista – 2017-05-10T11:24:14.870

If you say that's ok, then I will change it. – stevefestl – 2017-05-10T11:24:18.227

i count 112 bytes, you have extra spaces in 1st line – Felipe Nardi Batista – 2017-05-10T11:26:16.073

i counted 120 bytes, does [cr\lf] count as 1 byte? – stevefestl – 2017-05-10T11:27:20.447

yes, 1 byte as \n – Felipe Nardi Batista – 2017-05-10T11:27:58.767

i'll change.... – stevefestl – 2017-05-10T11:28:19.960

0

C#, 72 bytes

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

chrixbittinx

Posted 2017-05-07T14:33:52.477

Reputation: 65

-1

This may be foul play.

Bash, 24 Bytes

ping 192.0.0.8 -rqc50|wc

To verify +6 bytes

ping 192.0.0.8 -rqc50|tail -n2

192.0.0.8 is IPv4 dummy address. It send packet for 50 times in one second interval because it would not be reached.

okud

Posted 2017-05-07T14:33:52.477

Reputation: 99

That's includes in functions that wait for time. And woundn't that print stuff like unreachable dest? – Felipe Nardi Batista – 2017-05-09T15:33:38.267

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. http://s-macke.github.io/jor1k/demos/main.html Try:ping 192.0.0.8 -qc50|wc)

– okud – 2017-05-09T17:09:06.887