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.
Related, but different in subtle ways that make approaches to the old challenge inapplicable here: Is it Christmas?
– Dennis – 2015-11-26T15:56:03.7931I 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