Legen… wait for it…

70

3

dary!

In events entirely unrelated to what will hopefully happen to me in the next couple of days, I task you to write code that does the following:

  1. Print

    Legen... wait for it...
    

    immediately, with a trailing newline.

  2. Wait until the next full hour (when the cron job for awarding the badge runs).

  3. Print

    dary!
    

    with an optional trailing newline.

Additional rules

  • You may write a program or a function, but the output has to be printed to STDOUT (or its closest alternative of your language).

  • You have to wait until the next full hour, not just for 60 minutes. If the code is run at 6:58, it should print the second line at 7:00.

  • The last line must be printed no later than one second after the next full hour.

  • In the event that the program is started in the first second of a full hour, it should it wait for the next full hour.

  • You may query local or UTC time.

  • Standard rules apply.

Dennis

Posted 2015-11-26T15:55:57.660

Reputation: 196 637

Related, but different in subtle ways that make approaches to the old challenge inapplicable here: Is it Christmas?

– Dennis – 2015-11-26T15:56:03.793

1I don't understand how the third additional rule differs from the basic "wait until the next full hour" – Fatalize – 2015-11-26T15:59:42.323

2@Fatalize That's just a clarification that you have to wait until the hour changes, not until the minutes and seconds are both at 00. – Dennis – 2015-11-26T16:45:55.033

25Happy Legendary Badge, @Dennis! – user41805 – 2015-11-26T19:49:25.883

36@ΚριτικσιΛίθος Thanks! (Thank god for tab-completion.) – Dennis – 2015-11-26T19:50:21.330

2"On the hour" would be a more standard (and I believe much more clear) way of describing what you call "the next full hour" (at least in American English). – jpmc26 – 2015-11-28T01:05:47.897

Answers

12

Pyth, 42 41

J.d6." wâ«­hÖ`Ùá©h´^"WqJ.d6;"dary!

Below is a hexdump of the code:

00000000  4a 2e 64 36 2e 22 20 77  0c 10 89 e2 ab 1b ad 68  |J.d6." w.......h|
00000010  0f 8c d6 60 d9 e1 a9 68  82 b4 5e 22 57 71 4a 2e  |...`...h..^"WqJ.|
00000020  64 36 3b 22 64 61 72 79  21                       |d6;"dary!|

Saved 1 byte thanks to @isaacg

Uses the .d function to get local time related values. .d6 returns the current hour. This prints the first string, then waits until the hour is different from the hour ad the start of the program, and then prints the second string.

You could try it online with .d7 or .d8 for minutes/seconds but the online compiler only prints anything when the program terminates.

Congrats, Dennis! :)

FryAmTheEggman

Posted 2015-11-26T15:55:57.660

Reputation: 16 206

The string can be compressed by 1 bytes using packed-str. Hexdump: 0000000: 2e22 2077 0c10 89e2 ab1b ad68 0f8c d660 ." w.......h...` 0000010: d9e1 a968 82b4 5e22 0a ...h..^". – isaacg – 2015-11-26T18:21:55.790

@isaacg Whoops, I had checked that but I must have messed up counting. I thought it only compressed 1 byte so the extra . would make it the same length. Silly off-by-one errors :P – FryAmTheEggman – 2015-11-26T22:12:49.057

Just trying to figure out what this might do (with no experience with pyth at all) made me laugh. I see dary, but no legen! And pyth claims to be easier to understand by those used to conventional programming... – Cyoce – 2015-12-15T07:01:01.557

@Cyoce If you look in the edit history you can find an easier to read version. The ." indicates that the string should have some operations performed on it to get the real string. It's just a compression trick for golfing. If you decide to try to learn Pyth, best of luck! Don't forget there is a chatroom for it too :)

– FryAmTheEggman – 2015-12-15T13:55:29.480

26

JavaScript (ES6), 74 bytes

You may want to change your system clock before testing, congratulations if you landed here at 59 minutes past.

setTimeout(a=alert,36e5-new Date%36e5,"dary!");a`Legen... wait for it...
`

George Reith

Posted 2015-11-26T15:55:57.660

Reputation: 2 424

11Would 36e5 work in place of 3.6e6? – ETHproductions – 2015-11-26T17:23:04.450

8@ETHproductions You beauty! – George Reith – 2015-11-26T17:26:28.160

3@ETHproductions That is some bad scientific notation. I had no idea it worked on Javascript. Learned something today!!! – Ismael Miguel – 2015-11-26T18:08:34.770

"a\dary!`",new Date%36e5` – Optimizer – 2015-11-26T18:28:02.560

Also, alert is such bad word that storing it in a local variable for a single extra use case does not help in golfing ;) – Optimizer – 2015-11-26T18:32:57.153

2@Optimizer Ah didn't know setTimeout would eval for me. True... I was originally trying to use console.log but that doesn't even work when stored in a variable due to context. You too are beautiful! – George Reith – 2015-11-26T18:57:58.990

Also, at this point, you can skip the | and simply replace it with ,. Same difference though :) – Optimizer – 2015-11-26T19:02:12.853

Hah! I got here at 2 minutes past the hour! – user253751 – 2015-11-27T07:03:10.590

1You could use setTimeout properly and even save one byte: alert`Legen…`;setTimeout(alert,36e5-new Date%36e5,"dary!") – Bergi – 2015-11-27T08:15:05.693

1…and then two more: setTimeout(a=alert,36e5-new Date%36e5,"dary!");a`Legen…` – Bergi – 2015-11-27T08:19:42.257

Ha, nice one. :-) – Elliot Bonneville – 2015-11-27T17:22:19.013

Neither setTimeout nor alert are part of EcmaScript 6, these are rather from the HTML side of things. As for the use of alert, this also makes the solution non-portable as alert: 1) can optionally pause until the user acknowledges the message (which is how actual browsers tend to implement it) and 2) is not required to print messages on separate lines (actual browsers tend to use modal dialog windows), which means this does not necessarily produce the required results unless executed in a particular (unstated) environment. – Håkan Lindqvist – 2015-11-28T12:56:54.867

1@HåkanLindqvist tagged template strings are ES6, I don't feel the need to specify a HTML spec, I think that would just be pedantry. Dialogs can and do contain newlines in most popular browsers. The rest while true if Dennis wants to declare invalid the usage of alert I will happily change it to console.log. I had similar reservations but saw other answers being generally accepted with it so used it also to be competitive. – George Reith – 2015-11-28T13:14:30.317

@Bergi Nice! Surely we have peaked now. – George Reith – 2015-11-28T13:19:40.137

@GeorgeReith check out my solution for 66 bytes, which is valid for any JavaScript REPL console. By compiling it into Bean I golfed it down to 58 ;)

– Patrick Roberts – 2018-09-28T22:45:15.677

9

CJam, 49 48 bytes

et3="Legen... wait for it...
"o{_et3==}g;"dary!"

Uses local time. For testing purposes, you can replace the two instances of 3 with 4 or 5 to make it print at the start of the next minute/second.

Test it here. But note that the online interpreter doesn't show any output until the program terminates. Alternatively, you can run it on Try it online, where the output is shown almost immediately instead of being buffered (but when you test it with seconds instead of hours, the delay will be noticeable). In any case, if you run it locally with the Java interpreter, it works like a charm.

Explanation

This makes use of CJam's et which gives you an array of

[year month day hour minute second ms weekday utc_offset]

Here is a breakdown of the code:

et3=       e# Get the current hour.
"Legen..." e# Push the first string including the linefeed.
o          e# Print it.
{          e# While the top of stack is truthy (which is popped)...
  _        e#   Copy the original hour.
  et3=     e#   Get the current hour.
  =        e#   Check for equality.
}g
;          e# Discard the original hour.
"dary!"    e# Push the second string which is printed automatically.

Bonus

This also works for the same byte count:

et4<"Legen... wait for it...
"o{et1$#!}g;"dary!"

Instead of selecting the hour, we're selecting the prefix with the date and the hour, and keep the loop going while the datetime array still has that prefix.

Martin Ender

Posted 2015-11-26T15:55:57.660

Reputation: 184 808

9

AppleScript, 157 149 bytes

Huh. Surprisingly contending.

set d to number 1 in time string of(current date)
log"Legen... wait for it..."
repeat while d=number 1 in time string of(current date)
end
log"dary!"

Since log prints to the Messages pane of Script Editor, I consider it to be the closest output to STDOUT. Basically, if you get the time string of current date, it'll do something like this:

Code:

time string of(current date)

Output:

5:02:03 PM

It will grab the first number (5) before the colon.

I thought it'd be a lot longer than this, actually. xD

Addison Crump

Posted 2015-11-26T15:55:57.660

Reputation: 10 763

So what happens if you run it at 03:03:00? – Blacklight Shining – 2015-11-27T17:58:03.277

@BlacklightShining It will get the number 3 at the front and wait until it is four. It is only aware of the number before the colon. – Addison Crump – 2015-11-27T18:06:35.013

Oh, I missed that. Okay. Oddly enough, I'm actually getting just "1" from number 1 in time string of(current date) – Blacklight Shining – 2015-11-30T03:48:49.077

@BlacklightShining You're likely using an older version - in El Capitan, this is equivalent to first number in time string of (current date). – Addison Crump – 2015-12-03T11:16:23.250

I'm on Yosemite, yeah. first number also gives me just the first digit of the time ("0" right now, at 04:38). – Blacklight Shining – 2015-12-08T12:38:14.037

@BlacklightShining Odd. Next time I get on the computer, I'll record a run of it and YouTube it or something. – Addison Crump – 2015-12-08T22:01:57.453

8

Snowman 1.0.2, 70 69 bytes

~"Legen... wait for it...
"sP3600000*vt#nDnC!*:vt+#nD!#nL;bD"dary!"sP

Explanation:

~              Make all variables active.
"..."sP        Print the first string.
3600000*vt#nD  Get the number of hours since the Unix epoch.
nC             Ceiling (round up), giving the time (divided by 36000) at which to
                 print the second string.
!*             Save that in a permavar.
:...;bD        Do the stuff in the block while its "return value" is truthy.
  vt+#nD       Again, get the number of hours since epoch.
  !#             Store the permavar that we saved earlier.
  nL             Is the current time less than the target time? (if so,
                   keep looping)
"..."sP        Print the second string.

Doorknob

Posted 2015-11-26T15:55:57.660

Reputation: 68 138

7

PHP, 76, 70, 65, 62 51 bytes

Legen... wait for it...
<?while(+date(is));?>dary!

Previous logic (63b):

Legen... wait for it...
<?for($h=date(G);date(G)==$h;)?>dary!

This kind of coding makes you loose your job, but this loops until the time is 1 hour further than init.

-1 byte by replacing {} afer the while to ; (thanks manatwork)
-5 bytes by replacing echo'dary!'; to ?>dary! (thanks manatwork)
-4 bytes by replacing <?php to the short version <? (thanks primo)
-1 byte by replacing the while for a for
-3 bytes by replacing date(G)!=$h+1 to date(G)==$h (thanks primo)

Martijn

Posted 2015-11-26T15:55:57.660

Reputation: 713

Nice one, but {}; and echo?> would reduce it a bit. Though I would prefer Legen... wait for it...↵<?php while(+date('is'));?>dary! – manatwork – 2015-11-27T09:08:58.987

1A few tips: you can use short open tags (just <? rather than <?php). Using for(;;) is the same length as while(), but allows you to move the $h assignment, without needing a semi-colon (for($h=date(h);...). The {} weren't necessary, but neither is the ; preceding ?>. You may have a problem with $h is 12, though (date(h) will never be 13). – primo – 2015-11-27T09:13:57.193

Thank you both, updated my answer accordingly. Im not feeling too well, guess I shouldnt do important work today, because it clearly shows haha – Martijn – 2015-11-27T09:21:44.803

I stand corrected, I almost need to add you as a co-author to my answer – Martijn – 2015-11-27T09:32:50.910

2Change date(G)!=$h+1 to date(G)==$h. Shorter, and solves the hour problem ;) Also, remove the semi-colon before ?>. – primo – 2015-11-27T09:37:29.740

Just my curiosity, but is there a technical issue that I missed with the +date('is') condition I suggested? Or just feeling it is too different? – manatwork – 2015-11-27T09:48:26.367

Nope, just didn't look into it. I like the way it works, clever. The quotes arent needed, so removed those and updasted my answer – Martijn – 2015-11-27T09:50:23.890

1@manatwork it will fail to wait if the code is run at HH:00:00, i.e. within the first second of a full hour. – primo – 2015-11-27T09:54:19.590

You could overcome that by using u for microseconds, but that would required the script to hit every microseconds or it'll wait another hour – Martijn – 2015-11-27T09:57:10.247

Wait, is isn't a keyword? Learn something new every day... – primo – 2015-11-27T10:00:04.293

Oops. Missed that. Thank you @primo. And sorry Martijn. – manatwork – 2015-11-27T10:00:04.930

You could use the u for microseconds, lowering the chances to almost none, but the code would have to loop that exact microsecond. – Martijn – 2015-11-27T10:17:54.060

7

Perl 6, 60 bytes

sleep 60²-now%60²+say 'Legen... wait for it..';say 'dary!'

Brad Gilbert b2gills

Posted 2015-11-26T15:55:57.660

Reputation: 12 713

4

I would like to note that 60² was just added a few days ago

– Brad Gilbert b2gills – 2015-11-28T19:08:42.737

Wow, so close to being ineligible for this challenge! – cat – 2015-12-15T14:04:00.980

Congrats on 10k! – MD XF – 2017-11-19T02:29:03.397

5

Javascript 94 90 87 bytes

Not golfed that much...

alert`Legen... wait for it...`,l=l=>~~(Date.now()/36e5);for(z=l();z==l(););alert`dary!`

Downgoat's version:

(a=alert)`Legen... wait for it...`,z=(b=new Date().getHours)();for(;z==b(););a`dary!`

It stores the current hour and loops for as long as the "old" hour is equal to the current one. As soon as the hour has changed, it will print the rest! :D

Disclaimer: If your browser dislikes it, you have been warned.

Stefnotch

Posted 2015-11-26T15:55:57.660

Reputation: 607

287 bytes: (a=alert)\Legen... wait for it...`,l=new Date,z=(b=l.getHours)();for(;z==b(););a`dary!`` – Downgoat – 2015-11-26T16:21:08.583

@Downgoat Thanks! (I am trying to golf it right now..) – Stefnotch – 2015-11-26T16:26:25.777

1Even shorter (85 bytes): (a=alert)\Legen... wait for it...`,z=(b=new Date().getHours)();for(;z==b(););a`dary!`` – Downgoat – 2015-11-26T16:37:17.030

2@Downgoat One byte shorter: for((a=alert)`Legen... wait for it...`,z=(b=new Date().getHours)();z==b(););a`dary!` – Ismael Miguel – 2015-11-26T18:26:13.067

4

C, 163 bytes

#include<time.h>
f(){puts("Legen... wait for it...");time_t t=time(0);struct tm l=*localtime(&t);while(l.tm_min+l.tm_sec)t=time(0),l=*localtime(&t);puts("dary!");}

Zaglo

Posted 2015-11-26T15:55:57.660

Reputation: 41

3Welcome to PPCG! – Erik the Outgolfer – 2016-11-19T16:59:43.337

155 bytes (don't bother running it on TIO, it won't finish, it times out after one minute) – MD XF – 2017-11-19T02:31:56.687

4

Python 2, 82 81 bytes

from time import*;print'Legen... wait for it...';sleep(-time()%3600);print'dary!'

Too low a reputation to comment. Python 2 version of Alexander Nigl's solution. Saves characters lost on brackets. Also, 3600 not needed in the sleep time calculation.

7 characters saved overall.

Edit: -1 byte thanks to @Kevin Cruijssen

Henry T

Posted 2015-11-26T15:55:57.660

Reputation: 381

1

One additional byte can be saved by removing the trailing ; at the end of the program. Seems to work fine without it. :) Nice answer though, so +1 from me (now you can comment).

– Kevin Cruijssen – 2019-01-16T12:42:48.430

thanks loads @KevinCruijssen – Henry T – 2019-01-16T12:47:28.850

4

Mathematica, 85 84 81 bytes

c=Print;c@"Legen... wait for it...";a:=DateValue@"Hour";b=a;While[a==b];c@"dary!"

LegionMammal978

Posted 2015-11-26T15:55:57.660

Reputation: 15 731

I think you can save 2 bytes by making "dary!" the expression output. – CalculatorFeline – 2016-02-29T05:09:22.200

@CatsAreFluffy Then it would just be a snippet and not a full program. – LegionMammal978 – 2016-02-29T11:07:40.273

So? Isn't expression output acceptable in Mathematica, or am I missing something? – CalculatorFeline – 2016-02-29T16:15:06.183

@CatsAreFluffy Mathematica scripts exist, so any given full program is expected to run in one. – LegionMammal978 – 2016-02-29T21:56:45.007

4

MATLAB - 89 bytes

a=@()hour(now);disp('Legen... wait for it...');while(mod(a()+1,24)~=a())end;disp('dary!')

Pretty self-explanatory. First, create a function handle to grab the current hour of the system clock. Then, display Legen... wait for it... with a carriage return, and then we go into a while loop where we keep checking to see if the current hour added with 1 is not equal to the current hour. If it is, keep looping. Only until the instant when the next hour happens, we display dary! and a carriage return happens after.

MATLAB's hour is based on 24-hour indexing, so the mod operation with base 24 is required to handle spilling over from 11 p.m. (23:00) to midnight (00:00).

Minor Note

The hour function requires the Financial Time Series toolbox. The now function is not subject to this restriction, but it retrieves the current date and time as a serial number which hour thus uses to compute the current hour.

Want to run this in Octave?

Sure! Because Octave doesn't have this toolbox, we'd just have to modify the hour function so that it calls datevec which returns a vector of 6 elements - one for each of the year, month, day, hour, minutes and seconds. You'd just have to extract out the fourth element of the output:

a=@()datevec(now)(4);disp('Legen... wait for it...');while(mod(a()+1,24)~=a())end;disp('dary!')

The additional characters make the solution go up to 98 bytes, but you'll be able to run this in Octave. Note the in-place indexing without a temporary variable in the function handle.

No Financial Time Series Toolbox?

If you want to run this in MATLAB without the Financial Time Series Toolbox, because you can't index into variables immediately without at temporary one, this will take a bit more bytes to write:

disp('Legen... wait for it...');h=datevec(now);ans=h;while(mod(h(4)+1,24)~=ans(4)),datevec(now);end;disp('dary!');

This first obtains the current time and date and stores it into the variable h as well as storing this into the automatic variable called ans. After, we keep looping and checking if the current hour isn't equal to the next hour. At each iteration, we keep updating the automatic variable with the current time and date. As soon as the next hour matches with the current time and date, we display the last part of the string and quit. This pushes the byte count to 114.


Also take note that you can't try this online. Octave interpreters online will have a time limit on when code executes, and because this is a whileloop waiting for the next hour to happen, you will get a timeout while waiting for the code to run. The best thing you can do is run it on your own machine and check that it works.

rayryeng - Reinstate Monica

Posted 2015-11-26T15:55:57.660

Reputation: 1 521

In your first one you could save 3 bytes by instead checking now in the while loop: a=@()disp('Legen... wait for it...');while floor(mod(now*86400,3600))end;disp('dary!'). You could also save a further 5 bytes by removing the a=@() bit because as-is the code constitutes a full program. The attached code also doesn't require the FTS toolbox. – Tom Carpenter – 2015-11-27T00:15:48.640

How on Earth did you know about Financial Toolbox hour function? :-) – Luis Mendo – 2015-11-27T01:15:00.850

Now I see what you meant by your comment about needing intermediate variables for indexing... – Luis Mendo – 2015-11-27T01:15:48.953

3

Microscript II, 45 bytes

"Legen... wait for it..."P[36s5E*sD%_]"dary!"

Finally, a use for the D instruction.

Prints the first string, repeatedly takes the UTC time in milleseconds modulo 3,600,000 until this yields 0, and then produces the second string which is printed implicitly. The 3,600,000 is represented in the code as 36x105.

SuperJedi224

Posted 2015-11-26T15:55:57.660

Reputation: 11 342

Can you add an explanation? c: – Addison Crump – 2015-11-26T17:36:59.483

@VoteToClose Done – SuperJedi224 – 2015-11-26T17:45:20.563

3

TI-BASIC, 70 64 bytes

getTime
Disp "Legen... wait for it...
Repeat sum(getTime-Ans,1,1
End
"dary

Curse these two-byte lowercase letters!

getTime returns a three-element list {hours minutes seconds}, so the sum from the 1st element to the 1st is the hours. When there is a difference between the hours at the start and the current hours, the loop ends. Thanks to @FryAmTheEggman for this observation.

lirtosiast

Posted 2015-11-26T15:55:57.660

Reputation: 20 331

3

R - 97 bytes

cat('Legen... wait for it...\n')
Sys.sleep(1)
while(as.double(Sys.time())%%3600>0){}
cat('dary!')

jbaums

Posted 2015-11-26T15:55:57.660

Reputation: 181

3

Python 3 - 92 89 bytes

from time import*;print("Legen... wait for it...");sleep(3600-time()%3600);print("dary!")

Alexander Nigl

Posted 2015-11-26T15:55:57.660

Reputation: 121

2

Powershell, 52 51 bytes

-1 byte thanks @Veskah

'Legen... wait for it...'
for(;Date|% M*e){}'dary!'

This expression Date|% M*e gets value from Minute property from the Current DateTime value. The loop ends when Minute equal to 0.

mazzy

Posted 2015-11-26T15:55:57.660

Reputation: 4 832

1You should be able to put the 'dary' directly after the braces, or at least you can in PSv5. – Veskah – 2018-09-28T03:57:29.110

2

Japt, 72 61 bytes

`{?tT?e?t(Ã?t,36e5-?w D?e%36e5,'ÜÝ!'),'Leg?... Ø2 f? ?...\n'}

Each ? represents a Unicode unprintable char. Here's how to obtain the full text:

  1. Open the online interpreter.
  2. Paste this code into the Code box:
Oc"`\{setTimeout(alert,36e5-new Date%36e5,'dary!'),'Legen... wait for it...\\n'}
  1. Run the code, then erase it from the Code box.
  2. Select the contents of the Output box and drag to the Code box. Copy-pasting will not work.
  3. Replace the first space with a non-breaking space.
  4. (optional) Set your computer's clock to xx:59.
  5. Run the code.

Alternatively, here is a (hopefully reversible) hexdump:

00000000: 607b a074 548b 658c 7428 c300 742c 3336 65    `{ tT?e?t(Ã?t,36e
00000011: 352d 9a77 2044 8565 2533 3665 352c 27dc dd    5-?w D?e%36e5,'ÜÝ
00000022: 2127 293b 274c 6567 812e 2e2e 20d8 3220 66    !'),'Leg?... Ø2 f
00000033: 8e20 8a2e 2e2e 5c6e 277d                      ? ?...\n'}

This code is based on George Reith's JavaScript answer, with a few Japt-specific changes. I found out the other day that if you compress code and insert it into a backtick-wrapped string, it will automatically decompress. Here's how it's processed through compilation:

`{?tT?e?t(Ã?t,36e5-?w D?e%36e5,'ÜÝ!'),'Leg?... Ø2 f? ?...\n'}
"{setTimeout(alert,36e5-new Date%36e5,'dary!'),'Legen... wait for it...\n'}"
""+(setTimeout(alert,36e5-new Date%36e5,'dary!'),'Legen... wait for it...\n')+""

In JS, a pair of parentheses will return the last value inside; thus, this code sets the timed event, then returns the 'Legen...' string, which is automatically sent to STDOUT. Since Japt currently has no way to add content to STDOUT other than automatic output on compilation, I've instead used the vanilla JS function alert for the timed output. I hope this is allowed.

ETHproductions

Posted 2015-11-26T15:55:57.660

Reputation: 47 880

Can you post a hexdump of this? – a spaghetto – 2015-11-27T02:11:48.527

@quartata Done. I believe it's correct. – ETHproductions – 2015-11-27T04:26:52.853

2

Windows Command Script, 87 bytes

@set.=%time:~,2%&echo.Legen... wait for it...
:.
@if %.%==%time:~,2% goto:.
@echo.dary!

This continually compares an hour-variable stored at start against the current hour and succeeds if different.

Robert Sørlie

Posted 2015-11-26T15:55:57.660

Reputation: 1 036

2

Perl, 62 bytes

sleep -++$^T%3600+print'Legen... wait for it...
';print'dary!'

The special variable $^T (a.k.a $BASETIME) records the number seconds since epoch from when the script was started. Fortunately, leap seconds are not counted in the total, so that the following are equivalent:

print$^T%3600;
@T=gmtime;print$T[1]*60+$T[0];

Surprisingly, this variable is not read-only.

primo

Posted 2015-11-26T15:55:57.660

Reputation: 30 891

Not counting -E seems to the commonplace here, so you could save 5 bytes by using say. – Dennis – 2015-11-27T01:41:42.827

From the challenge description: "You may write a program or a function." Code run from the command line is neither. – primo – 2015-11-27T01:51:02.470

I see your point. However, the restriction to programs or functions applies to all challenges by default, yet we still allow perl -E submissions and languages that only have online interpreters. – Dennis – 2015-11-27T01:54:19.087

I disagree that -E should be allowed by default. In most cases, the improvement is trivial and uninteresting, anyway. – primo – 2015-11-27T02:07:05.573

1

Jelly, 48 47 bytes, non-competing

-1 byte thanks to Erik the Golfer (use "Leg" as a word in the compression)

“ÇỴġƒḃhlḂṀ⁷*Ḣ¡w*Jḷv»Ṅø3ŒTṣ”:V_@59ḅ60‘œS@“dary!”

TryItOnline! or run a test version with a hard coded time-formatted-string of “59:57” ("mm:ss").

Jelly's first commit was made by Dennis just days after he created this challenge, I'm not sure on what date this code would have first worked, but it is non-competing in any case.
There is, at the time of writing, only one way to access the time which is by way of a formatted string, ŒT.

This code calculates how long to wait and then sleeps. If called at hh:00:00 it waits for 3600 seconds: it converts "00:00" to [0,0] then subtracts that from 59 to yield [59,59], converts that from base sixty to give 3599, then adds one for a total wait period of 3600 seconds.

Maybe a loop could be made; or a compressed string using the whole word "Legendary" could be utilised somehow?

“ÇỴġƒḃhlḂṀ⁷*Ḣ¡w*Jḷv»Ṅø3ŒTṣ”:V_@59ḅ60‘œS@“dary!” - Main link: no arguments
“ÇỴġƒḃhlḂṀ⁷*Ḣ¡w*Jḷv»                            - compressed "Legen... wait for it..."
                    Ṅ                           - print z + '\n', return z
                     ø                          - niladic chain separation
                      3ŒT                       - '011' (3) time formatted string = "mm:ss"
                         ṣ”:                    - split on ':' -> ["mm","ss"]
                            V                   - eval -> [m,s]
                             _@59               - subtract from 59 - > [59-m, 59-s]
                                 ḅ60            - convert from base 60 -> 60*(59-m)+(59-s)
                                    ‘           - increment -> 60*(59-m)+(59-s) = y
                                        “dary!” - "dary!" = x
                                     œS@        - sleep y seconds then return x
                                                - implicit print

Jonathan Allan

Posted 2015-11-26T15:55:57.660

Reputation: 67 804

1Use “ÇỴġƒḃhlḂṀ⁷*Ḣ¡w*Jḷv» instead of “¤ßƇṪOƭ!½ȯƤxEẹ<Ȯ¹z7⁷». Leg (from Legen) is also a word :) Also, this answer is invalid, because it depends on the minutes and the seconds both being 00. You should do something with 4ŒT instead, since there is a rule stating that, In the event that the program is started in the first second of a full hour, it should it wait for the next full hour. – Erik the Outgolfer – 2016-11-20T11:54:22.287

Cool, "Leg" saves a byte, thanks. However, the link does work at when called at 00:00 as it is not testing for that condition - it calculates how many seconds until the next "00:00" and then waits. So it would convert "00:00" to [0,0] subtract from 59 to yield [59,59] convert that from base sixty to get 3599 and then add one to get 3600 (test it using the test version with "00:00" in place of "59:57") – Jonathan Allan – 2016-11-20T19:56:52.503

1Oh. It seems I can't read long Jelly code, and that I can't know everyone's uses and expectations :) Although, in the explanation, I think that 60*(59-m)+(59-s) must be 60*(59-m)+(59-s)+1 instead, the second time it appears? – Erik the Outgolfer – 2016-11-20T20:00:00.897

No problem - the commentary isn't the clearest I've ever written. – Jonathan Allan – 2016-11-20T20:02:28.150

Well, if you can't take the hassle, I can edit it in. Also, I would recommend doing x/y as left/right, and just say sleep x seconds then return y—because <dyad>@ can be defined as another dyad with swapped args. – Erik the Outgolfer – 2016-11-20T20:06:13.470

1

MathGolf, 39 bytes

"Legen... wait for it..."pÆt♪/╚÷▼"dary!

Try it online!

Almost beat pyth...

Explanation

Æ     ▼  Repeat the next 5 characters while false
 t       push unix time in milliseconds
  ♪/     divide by 1000
    ╚÷   check if divisible by 3600 (tio solution has 3 in its place)

maxb

Posted 2015-11-26T15:55:57.660

Reputation: 5 754

"Almost"? It looks like you did. – Patrick Roberts – 2018-09-28T22:43:56.193

@PatrickRoberts there's another pyth solution that's 36 bytes, couldn't quite get there even with compressed strings and other tricks. – maxb – 2018-09-29T10:53:11.793

Oh that one. It's wrong, look at the comment. – Patrick Roberts – 2018-09-29T14:59:29.890

@PatrickRoberts I might fail on the "must wait one hour if run on 00:00” criterion too, but I could change it to check Unixtime in milliseconds divisible by 3600000 with the same byte count. Since the first print should take more than a millisecond, it should always work. – maxb – 2018-09-29T15:09:34.027

1

Befunge 98 - 69 63 bytes

 v
v>a"...ti rof tiaw ...negeL<ETB>"k,
>"EMIT"4(MS+_"!yrad"5k,@

The code contains one unprintable character (represented by <ETB> as unprintables don't seem to show up in code blocks). Its character code is 23 (an End transmission block character).

Warning: The preceding code will run in a busy loop with the stack getting bigger each repetition and thus may consume large amounts of memory.

pppery

Posted 2015-11-26T15:55:57.660

Reputation: 3 987

1

Python, 112 bytes

import time as t;print "Legen... wait for it...";n=t.ctime();t.sleep((60-n.tm_min)*60+60-n.tm_sec);print "dary!"

Pretty self explanatory.

agtoever

Posted 2015-11-26T15:55:57.660

Reputation: 2 661

Can save 2 by getting rid of the spaces between the print statements and the following strings. :) – Henry T – 2019-01-16T12:52:51.010

1

Python - 159 bytes

from datetime import*;from threading import*;p=print;n=datetime.now();p('Legen... wait for it...');Timer(3600-(n.minute*60+n.second),lambda:p('dary!')).start()

elzell

Posted 2015-11-26T15:55:57.660

Reputation: 111

1

Mouse-2002, 62 bytes

Requires the user to press enter. I think.

"Legen... wait for it..."?&HOUR 1+x:(&HOUR x.=["dary"33!'0^])

Okay, well, while we're taking lots of bytes and not winning anything, let's have a little fun.

"Legen... wait for it... "?     ~ print & require keypress

&HOUR 1+ x:                     ~ get hr, add 1 and assign
(                               ~ while(1)
  &HOUR x. =                    ~ cmp current hr, stored hr
  [                             ~ if same
    #B;                           ~ backspace
    "dary"36!'                    ~ print this string and a !
    0^                            ~ exit cleanly
  ]                             ~ fi
  &MIN 59 - &ABS !              ~ get min, subtract from 59, abs & print
  ":"                           ~ record sep
  &SEC 59 - &ABS !              ~ same for second
  #B;                           ~ backspace
)
$B 8!' 8 !' 8 !' 8 !' 8 !'@     ~ backspace 5*
$                               ~ \bye

Sample:

$ mouse legend.m02
Legen... wait for it... 20:32

See, it's an updating-in-place countdown timer to the next hour! It makes good use of the while loop, which even doing nothing at all will occupy a core.

cat

Posted 2015-11-26T15:55:57.660

Reputation: 4 989

1

BASIC, 90 bytes

Print"Legen... wait for it...":x$=Left(Time,2):Do:Loop Until x$<>Left(Time,2):Print"dary!"

Straightforward, golfed using the type prefixes and the implicit End statement. Cost is that it works only in FreeBasic dialect fblite.

user48538

Posted 2015-11-26T15:55:57.660

Reputation: 1 478

0

QBIC, 58 bytes

?@Legen... wait for it...|#Dary!|{~mid$$|(_d,4,2)=@00||_XB

Explanation

?@Legen... wait for it...|     Define string literal "Leg[..]it..." and print it
#Dary!|                        Define string B as "Dary!", but don't use it yet
{                              Opens an indefinite DO loop
~mid$$|(...)=@00|              Translates to IF MID$(...) = C$, where C$ is "00"
    The MID$ takes two characters, starting from pos 4, from the system's time (_d)
    So, if the string "11:00" has "00" starting at pos 4,
_XB                            Terminate the program and print string B
(The DO loop and the IF are closed implicitly)

steenbergh

Posted 2015-11-26T15:55:57.660

Reputation: 7 772

0

C#, 119 Bytes

Golfed:

var d=DateTime.Now;Console.Write("Legen... wait for it...");while(DateTime.Now.Hour!=d.Hour+1){}Console.Write("dary!");

Only needs using System; to run - I will add this into the byte count if it's required.

Outputs:

"Legen... wait for it..."

(Still waiting for the "dary!" to appear...)

Pete Arden

Posted 2015-11-26T15:55:57.660

Reputation: 1 151

1Did the "dary!" finally appear? Because I'm worried... – Erik the Outgolfer – 2016-11-20T20:12:17.263

1@Erik the Golfer It did you know! And I can tell you, it was worth the...wait! :) – Pete Arden – 2016-11-20T20:43:14.023

0

Pascal (FPC), 125 bytes

Uses sysutils;var t:real;begin t:=Now;writeln('Legen... wait for it...');while trunc(t*24)=trunc(Now*24)do;write('dary!')end.

Try it online! (Wait for the next minute version)

After digging through FPC's source code, I learned that return type of Now() (and Time() and Date()) is TDateTime which is the same as Double and Real and that the whole part is used for the date and the fractional part is used for the time. Multiplying Now() by 24 gives the number of hours in the whole part. The program saves the current time in t at the start and waits until the mutiplied whole part changes (by comparing truncated values).

AlexRacer

Posted 2015-11-26T15:55:57.660

Reputation: 979

0

Ruby, 66 bytes

Very straight forward, i guess

puts"Legen... wait for it...";sleep 60.*60-Time.now.min;puts:dary!

Håvard Nygård

Posted 2015-11-26T15:55:57.660

Reputation: 341

0

C (Windows API), 119 bytes

#include <Windows.h>
WORD s[8];main(){puts("Legen... wait for it...");do{GetLocalTime(s);}while(s[6]!=0);puts("dary!");}

Govind Parmar

Posted 2015-11-26T15:55:57.660

Reputation: 828

0

Bean, 58 bytes

Hexdump:

00000000: a653 d080 a038 2080 4023 8100 35cc d420  ¦SÐ. 8 .@#..5ÌÔ 
00000010: 218f 2581 0126 2381 02cc e5e7 e5ee aeae  !.%..&#..Ìåçåî®®
00000020: aea0 f7e1 e9f4 a0e6 eff2 a0e9 f4ae ae2e  ® ÷áéô æïò éô®®.
00000030: b3ae b6e5 36e4 e1f2 f921                 ³®¶å6äáòù!

Bean Interpreter

Equivalent JavaScript (66 bytes):

console.log("Legen... wait for it...")
while(new Date%36e5)"dary!"

On the Bean Interpreter, make sure not to run without Multithread enabled or you might crash your browser. If it's enabled you should have nothing to worry about though, as it runs the blocking while loop in a Web Worker.

Patrick Roberts

Posted 2015-11-26T15:55:57.660

Reputation: 2 475

0

F#, 117 bytes

let n()=System.DateTime.Now.Hour
let l=
 printfn"Legen... wait for it..."
 let o=n()
 while n()=o do()
 printf"dary!"

The brackets after the n turns it from a value into a function, so it will be re-evaluated every time it's accessed. Other than that, it's a fairly straight-forward while loop.

Ciaran_McCarthy

Posted 2015-11-26T15:55:57.660

Reputation: 689

0

SmileBASIC, 69 66 62 bytes

?"Legen... wait for it...
TMREAD OUT,M,
WAIT(60-M)*3600?"dary!

12Me21

Posted 2015-11-26T15:55:57.660

Reputation: 6 110

0

05AB1E, 34 37 bytes

”ëÃ!”2ä©н…šÏ€‡€•‚…...«ðý,[žbžc+_#}®θ,

+3 bytes because I forgot about rule "In the event that the program is started in the first second of a full hour, it should wait for the next full hour.".

Try it online (with the waiting put under a setting).

Explanation:

”ëÃ!”              # Push Titlecase dictionary word: "Legendary!"
     2ä            # Split it into two equal parts: ["Legen","dary!"]
       ©           # Save this list in the register (without popping)
н                  # Pop and only leave the first value: "Legen"
 …šÏ€‡€•           # Push three space-delimited dictionary words: "wait for it"
        ‚          # Pair them together: ["Legen","wait for it"]
         …...      # Push string "..."
             «     # Append them after each item: ["Legen...","wait for it..."]
              ðý   # Join by spaces: "Legen... wait for it..."
                ,  # Print with a trailing newline
[       }          # Start an infinite loop
 žb                #  Push the current minutes
   žc+             #  Add the current seconds
      _            #  Check if the minutes and seconds combined are exactly 0
       #           #  And if they are 0: stop the infinite loop
®                  # Push the list from the register again
 θ                 # Pop and only leave the last value: "dary!"
  ,                # Print it with trailing newline

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why ”ëÃ!” is "Legendary!" and …šÏ€‡€• is "wait for it".

Kevin Cruijssen

Posted 2015-11-26T15:55:57.660

Reputation: 67 575

0

Pyth - 36 bytes

Waits till the minutes is 0 with a while loop.

"Legen... wait for it..."W.d7)"dary!

Maltysen

Posted 2015-11-26T15:55:57.660

Reputation: 25 023

11You need to wait until the minutes and seconds are 0, and also wait a full hour if the program is run at :00:00 – lirtosiast – 2015-11-26T21:50:03.837

0

Java, 136 bytes

class a{void A(){System.out.println("Legen... wait for it...");while(System.currentTimeMillis()%3600000!=0);System.out.print("dary!");}}

How many milliseconds passed since the last full hour is the result of System.currentTimeMillis() mod 3,600,000.

The equivalent monolithic program is 159 bytes long:

interface a{static void main(String[]A){System.out.println("Legen... wait for it...");while(System.currentTimeMillis()%3600000!=0);System.out.print("dary!");}}

user8397947

Posted 2015-11-26T15:55:57.660

Reputation: 1 242