76
\$\begingroup\$

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.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ I don't understand how the third additional rule differs from the basic "wait until the next full hour" \$\endgroup\$
    – Fatalize
    Nov 26, 2015 at 15:59
  • 3
    \$\begingroup\$ @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. \$\endgroup\$
    – Dennis
    Nov 26, 2015 at 16:45
  • 27
    \$\begingroup\$ Happy Legendary Badge, @Dennis! \$\endgroup\$
    – user41805
    Nov 26, 2015 at 19:49
  • 42
    \$\begingroup\$ @ΚριτικσιΛίθος Thanks! (Thank god for tab-completion.) \$\endgroup\$
    – Dennis
    Nov 26, 2015 at 19:50
  • 3
    \$\begingroup\$ "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). \$\endgroup\$
    – jpmc26
    Nov 28, 2015 at 1:05

41 Answers 41

27
\$\begingroup\$

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

\$\endgroup\$
15
  • 12
    \$\begingroup\$ Would 36e5 work in place of 3.6e6? \$\endgroup\$ Nov 26, 2015 at 17:23
  • 9
    \$\begingroup\$ @ETHproductions You beauty! \$\endgroup\$ Nov 26, 2015 at 17:26
  • 3
    \$\begingroup\$ @ETHproductions That is some bad scientific notation. I had no idea it worked on Javascript. Learned something today!!! \$\endgroup\$ Nov 26, 2015 at 18:08
  • 2
    \$\begingroup\$ @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! \$\endgroup\$ Nov 26, 2015 at 18:57
  • 1
    \$\begingroup\$ You could use setTimeout properly and even save one byte: alert`Legen…`;setTimeout(alert,36e5-new Date%36e5,"dary!") \$\endgroup\$
    – Bergi
    Nov 27, 2015 at 8:15
12
\$\begingroup\$

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! :)

\$\endgroup\$
4
  • \$\begingroup\$ 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..^". \$\endgroup\$
    – isaacg
    Nov 26, 2015 at 18:21
  • \$\begingroup\$ @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 \$\endgroup\$ Nov 26, 2015 at 22:12
  • \$\begingroup\$ 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... \$\endgroup\$
    – Cyoce
    Dec 15, 2015 at 7:01
  • \$\begingroup\$ @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 :) \$\endgroup\$ Dec 15, 2015 at 13:55
9
\$\begingroup\$

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.

\$\endgroup\$
0
9
\$\begingroup\$

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

\$\endgroup\$
6
  • \$\begingroup\$ So what happens if you run it at 03:03:00? \$\endgroup\$ Nov 27, 2015 at 17:58
  • \$\begingroup\$ @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. \$\endgroup\$ Nov 27, 2015 at 18:06
  • \$\begingroup\$ Oh, I missed that. Okay. Oddly enough, I'm actually getting just "1" from number 1 in time string of(current date) \$\endgroup\$ Nov 30, 2015 at 3:48
  • \$\begingroup\$ @BlacklightShining You're likely using an older version - in El Capitan, this is equivalent to first number in time string of (current date). \$\endgroup\$ Dec 3, 2015 at 11:16
  • \$\begingroup\$ I'm on Yosemite, yeah. first number also gives me just the first digit of the time ("0" right now, at 04:38). \$\endgroup\$ Dec 8, 2015 at 12:38
8
\$\begingroup\$

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.
\$\endgroup\$
7
\$\begingroup\$

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)

\$\endgroup\$
12
  • \$\begingroup\$ Nice one, but {}; and echo?> would reduce it a bit. Though I would prefer Legen... wait for it...↵<?php while(+date('is'));?>dary! \$\endgroup\$
    – manatwork
    Nov 27, 2015 at 9:08
  • 1
    \$\begingroup\$ A 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). \$\endgroup\$
    – primo
    Nov 27, 2015 at 9:13
  • \$\begingroup\$ Thank you both, updated my answer accordingly. Im not feeling too well, guess I shouldnt do important work today, because it clearly shows haha \$\endgroup\$
    – Martijn
    Nov 27, 2015 at 9:21
  • 2
    \$\begingroup\$ Change date(G)!=$h+1 to date(G)==$h. Shorter, and solves the hour problem ;) Also, remove the semi-colon before ?>. \$\endgroup\$
    – primo
    Nov 27, 2015 at 9:37
  • 1
    \$\begingroup\$ @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. \$\endgroup\$
    – primo
    Nov 27, 2015 at 9:54
7
\$\begingroup\$

Perl 6, 60 bytes

sleep 60²-now%60²+say 'Legen... wait for it..';say 'dary!'
\$\endgroup\$
3
  • 4
    \$\begingroup\$ I would like to note that 60² was just added a few days ago \$\endgroup\$ Nov 28, 2015 at 19:08
  • \$\begingroup\$ Wow, so close to being ineligible for this challenge! \$\endgroup\$
    – cat
    Dec 15, 2015 at 14:04
  • \$\begingroup\$ Congrats on 10k! \$\endgroup\$
    – MD XF
    Nov 19, 2017 at 2:29
5
\$\begingroup\$

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.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ 87 bytes: (a=alert)`Legen... wait for it...`,l=new Date,z=(b=l.getHours)();for(;z==b(););a`dary!` \$\endgroup\$
    – Downgoat
    Nov 26, 2015 at 16:21
  • \$\begingroup\$ @Downgoat Thanks! (I am trying to golf it right now..) \$\endgroup\$
    – Stefnotch
    Nov 26, 2015 at 16:26
  • 1
    \$\begingroup\$ Even shorter (85 bytes): (a=alert)`Legen... wait for it...`,z=(b=new Date().getHours)();for(;z==b(););a`dary!` \$\endgroup\$
    – Downgoat
    Nov 26, 2015 at 16:37
  • 2
    \$\begingroup\$ @Downgoat One byte shorter: for((a=alert)`Legen... wait for it...`,z=(b=new Date().getHours)();z==b(););a`dary!` \$\endgroup\$ Nov 26, 2015 at 18:26
5
\$\begingroup\$

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

\$\endgroup\$
2
  • 1
    \$\begingroup\$ 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). \$\endgroup\$ Jan 16, 2019 at 12:42
  • \$\begingroup\$ thanks loads @KevinCruijssen \$\endgroup\$
    – Henry T
    Jan 16, 2019 at 12:47
4
\$\begingroup\$

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 while loop 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.

\$\endgroup\$
3
  • \$\begingroup\$ 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. \$\endgroup\$ Nov 27, 2015 at 0:15
  • \$\begingroup\$ How on Earth did you know about Financial Toolbox hour function? :-) \$\endgroup\$
    – Luis Mendo
    Nov 27, 2015 at 1:15
  • \$\begingroup\$ Now I see what you meant by your comment about needing intermediate variables for indexing... \$\endgroup\$
    – Luis Mendo
    Nov 27, 2015 at 1:15
4
\$\begingroup\$

Mathematica, 85 84 81 bytes

c=Print;c@"Legen... wait for it...";a:=DateValue@"Hour";b=a;While[a==b];c@"dary!"
\$\endgroup\$
4
  • \$\begingroup\$ I think you can save 2 bytes by making "dary!" the expression output. \$\endgroup\$ Feb 29, 2016 at 5:09
  • \$\begingroup\$ @CatsAreFluffy Then it would just be a snippet and not a full program. \$\endgroup\$ Feb 29, 2016 at 11:07
  • \$\begingroup\$ So? Isn't expression output acceptable in Mathematica, or am I missing something? \$\endgroup\$ Feb 29, 2016 at 16:15
  • \$\begingroup\$ @CatsAreFluffy Mathematica scripts exist, so any given full program is expected to run in one. \$\endgroup\$ Feb 29, 2016 at 21:56
4
\$\begingroup\$

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!");}
\$\endgroup\$
2
  • 3
    \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ Nov 19, 2016 at 16:59
  • \$\begingroup\$ 155 bytes (don't bother running it on TIO, it won't finish, it times out after one minute) \$\endgroup\$
    – MD XF
    Nov 19, 2017 at 2:31
3
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ Can you add an explanation? c: \$\endgroup\$ Nov 26, 2015 at 17:36
  • \$\begingroup\$ @VoteToClose Done \$\endgroup\$ Nov 26, 2015 at 17:45
3
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

R - 97 bytes

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

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.

\$\endgroup\$
4
  • \$\begingroup\$ Not counting -E seems to the commonplace here, so you could save 5 bytes by using say. \$\endgroup\$
    – Dennis
    Nov 27, 2015 at 1:41
  • \$\begingroup\$ From the challenge description: "You may write a program or a function." Code run from the command line is neither. \$\endgroup\$
    – primo
    Nov 27, 2015 at 1:51
  • \$\begingroup\$ 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. \$\endgroup\$
    – Dennis
    Nov 27, 2015 at 1:54
  • \$\begingroup\$ I disagree that -E should be allowed by default. In most cases, the improvement is trivial and uninteresting, anyway. \$\endgroup\$
    – primo
    Nov 27, 2015 at 2:07
3
\$\begingroup\$

Python 3 - 92 89 bytes

from time import*;print("Legen... wait for it...");sleep(3600-time()%3600);print("dary!")
\$\endgroup\$
0
2
\$\begingroup\$

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.

\$\endgroup\$
0
2
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ Can you post a hexdump of this? \$\endgroup\$ Nov 27, 2015 at 2:11
  • \$\begingroup\$ @quartata Done. I believe it's correct. \$\endgroup\$ Nov 27, 2015 at 4:26
2
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You should be able to put the 'dary' directly after the braces, or at least you can in PSv5. \$\endgroup\$
    – Veskah
    Sep 28, 2018 at 3:57
2
\$\begingroup\$

Jelly,  48 47  45 bytes

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

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

Try it online! Or run a test version with a hard coded time-formatted-string of “59:57” ("mm:ss"). (Note: TIO buffers output, but local runs work as expected.)

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ṣ”:V59_ḅ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
\$\endgroup\$
8
  • 1
    \$\begingroup\$ Use “ÇỴġƒḃ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. \$\endgroup\$ Nov 20, 2016 at 11:54
  • \$\begingroup\$ 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") \$\endgroup\$ Nov 20, 2016 at 19:56
  • 1
    \$\begingroup\$ Oh. 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? \$\endgroup\$ Nov 20, 2016 at 20:00
  • \$\begingroup\$ No problem - the commentary isn't the clearest I've ever written. \$\endgroup\$ Nov 20, 2016 at 20:02
  • \$\begingroup\$ 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. \$\endgroup\$ Nov 20, 2016 at 20:06
1
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Can save 2 by getting rid of the spaces between the print statements and the following strings. :) \$\endgroup\$
    – Henry T
    Jan 16, 2019 at 12:52
1
\$\begingroup\$

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()
\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
0
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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)
\$\endgroup\$
4
  • \$\begingroup\$ "Almost"? It looks like you did. \$\endgroup\$ Sep 28, 2018 at 22:43
  • \$\begingroup\$ @PatrickRoberts there's another pyth solution that's 36 bytes, couldn't quite get there even with compressed strings and other tricks. \$\endgroup\$
    – maxb
    Sep 29, 2018 at 10:53
  • \$\begingroup\$ Oh that one. It's wrong, look at the comment. \$\endgroup\$ Sep 29, 2018 at 14:59
  • \$\begingroup\$ @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. \$\endgroup\$
    – maxb
    Sep 29, 2018 at 15:09
1
\$\begingroup\$

Vyxal o, 36 bytes

`Le₁ǐ... ʁṁ λ⟑ it...`,kḢ{:kḢ=|}`d₴⁼!

Don't Try it Online!

In the online interpreter, all output happens at once, so you can't see exactly what's happening. However, if you download and run the interpreter, you can see that it functions as expected.

Explanation:

`Le₁ǐ... ʁṁ λ⟑ it...`                # Dictionary-compressed string "Legen... wait for it..."
                     ,               # Print with newline
                      kḢ{:kḢ= }      # While the current hour hasn't changed:
                             |       #  Do nothing
                               `d₴⁼! # Dictionary-compressed string "dary!"
                                     # "o" flag - Force implicit output
\$\endgroup\$
0
\$\begingroup\$

Pyth - 36 bytes

Waits till the minutes is 0 with a while loop.

"Legen... wait for it..."W.d7)"dary!
\$\endgroup\$
1
  • 11
    \$\begingroup\$ You need to wait until the minutes and seconds are 0, and also wait a full hour if the program is run at :00:00 \$\endgroup\$
    – lirtosiast
    Nov 26, 2015 at 21:50
0
\$\begingroup\$

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!");}}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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