17
\$\begingroup\$

Challenge

The challenge is simple:

Taking no inputs and output the following message:

 _     __    __
  |   |  | |   |
  |_  |__| |   | 

A number of times equal to the number of hours before or after midnight UTC on 31st Dec 2016.

Examples

For example if it is 19:01 UTC dec 31st you should output:

 _     __    __
  |   |  | |   |
  |_  |__| |   | 
 _     __    __
  |   |  | |   |
  |_  |__| |   | 
 _     __    __
  |   |  | |   |
  |_  |__| |   | 
 _     __    __
  |   |  | |   |
  |_  |__| |   | 
 _     __    __
  |   |  | |   |
  |_  |__| |   | 

if it is 23:24 UTC dec 31st you should output:

 _     __    __
  |   |  | |   |
  |_  |__| |   | 

and if it is 1:42 UTC jan 1st you should output:

 _     __    __
  |   |  | |   |
  |_  |__| |   | 
 _     __    __
  |   |  | |   |
  |_  |__| |   | 

Clarification: if it is 10-11pm dec 31st you should output two, 11-12pm dec 31st output one, 00-01am jan 1st output one, 01-02am jan 1st output two etc...

Rules

  • No Inputs
  • Trailing lines or spaces are ok.
  • Your program should work any time or day I run it (albeit with a large output). For example on jan 2nd at 00:15am your code should output 25 times.

(This is my first Code Golf question so if I have left any thing important out please let me know.)

This is Code Golf so Shortest bits win

\$\endgroup\$
  • \$\begingroup\$ Is the number of hours rounded to the nearest integer? If it's within a half-hour of the New-Year-midnight, should there be no output? \$\endgroup\$ – Greg Martin Dec 31 '16 at 10:08
  • \$\begingroup\$ @GregMartin See my edit for clarification. \$\endgroup\$ – Quantum spaghettification Dec 31 '16 at 10:10
  • \$\begingroup\$ What should happen if I run the program on 3 January? \$\endgroup\$ – betseg Dec 31 '16 at 10:16
  • \$\begingroup\$ @betseg ye I just thought about that to. See edit :). It should work the same even though the output will be large. \$\endgroup\$ – Quantum spaghettification Dec 31 '16 at 10:18
  • \$\begingroup\$ Nice first question. About rounding: the number of repetitions is the absolute value of the difference between current time UCT and 0:00:00 of Jan 1st UTC, rounded up. Correct? \$\endgroup\$ – edc65 Dec 31 '16 at 10:23
6
\$\begingroup\$

JavaScript (ES6), 107

As an anonymous method with no parameters

Note 1483228800000 is Date.UTC(2017,0)

_=>` _     __    __
  |   |  | |   |
  |_  |__| |   |
`.repeat((Math.abs(new Date-14832288e5)+36e5-1)/36e5)

Test This keeps updating every 1 minute, but you'll need a lot of patience to see the output change.

F=_=>`_     __    __
 |   |  | |   |
 |_  |__| |   |
`.repeat((Math.abs(new Date-14832288e5)+36e5-1)/36e5)

update=_=>O.textContent=F()

setInterval(update,60000)

update()
<pre id=O></pre>

\$\endgroup\$
4
\$\begingroup\$

Python 2 - 97 + 17 = 114 bytes

import time
print'_     __    __\n |   |  | |   |\n |_  |__| |   |\n'*int((abs(time.time()-1483228800)+3599)/3600)

Borrowed logic for ceiling from edc65's answer.

Python 3.5 - 116 bytes

import time,math
print('_     __    __\n |   |  | |   |\n |_  |__| |   |\n'*math.ceil(abs(time.time()/3600-412008)))

math.ceil returns an integer in 3.x whereas in 2.x it returns a float.

Thanks elpedro for saving 3 bytes.

\$\endgroup\$
  • \$\begingroup\$ @ElPedro Thanks. Was about to do that, in my previous solutions I was fiddling with datetime.now(pytz.utc).timestamp() which required python 3.5. \$\endgroup\$ – Gurupad Mamadapur Dec 31 '16 at 14:09
2
\$\begingroup\$

Pyth - 71 68 bytes

*"_     __    __
 |   |  | |   |
 |_  |__| |   |
".Ea412008c.d0 3600

Uses the same logic used in my python 3.5 answer.

Try it here!

\$\endgroup\$
  • \$\begingroup\$ @Quantumspaghettification Isn't this shorter? \$\endgroup\$ – Gurupad Mamadapur Jan 15 '17 at 22:24
2
\$\begingroup\$

C compiled with Clang 3.8.1 327 317 145 Bytes

172 bytes saved thanks to @edc65

#include <time.h>
t;main(){time(&t);t=abs(difftime(t,1483228800)/3600);while(t--)puts(" _     __    __\n  |   |  | |   |\n  |_  |__| |   |\n");}

Ungolfed

#include <time.h>
t;
main()
{
time(&t);

t=difftime(t, 1483228800)/3600;

while(t--)
    puts(" _     __    __\n  |   |  | |   |\n  |_  |__| |   |\n");
}

317 bytes

10 bytes saved thanks to @LegionMammal978

#include <time.h>
t,y,w;main() {struct tm n;time(&t);n=*localtime(&t);n.tm_hour=n.tm_min=n.tm_sec=n.tm_mon=0;n.tm_mday=1;w=n.tm_year;if((w&3)==0&&((w % 25)!=0||(w & 15)==0))w=8784;else w=8760;t=(int)difftime(t, mktime(&n))/3600;t=t<w/2?t:w-t;for(;y++<t;)puts(" _     __    __\n  |   |  | |   |\n  |_  |__| |   |\n");

Ungolfed

#include <time.h>
t,y,w;
main()
{
    struct tm n;
    time(&t);

    n=*localtime(&t);

    n.tm_hour=n.tm_min=n.tm_sec=n.tm_mon=0;
    n.tm_mday=1;
    w=n.tm_year;

    if((w&3)==0&&((w % 25)!=0||(w & 15)==0))w=8784;else w=8760;

    t=(int)difftime(t, mktime(&n))/3600;
    t=t<w/2?t:w-t; 

    for(;y++<t;)
        puts(" _     __    __\n  |   |  | |   |\n  |_  |__| |   |\n");
}

I will add some explanations when I'll be able to.

\$\endgroup\$
  • \$\begingroup\$ Aren't you able to do n.tm_hour=n.tm_min=...=n.tm_mon=0;? \$\endgroup\$ – LegionMammal978 Dec 31 '16 at 13:43
  • \$\begingroup\$ @LegionMammal978 Oh yeah, I forgot. Thanks. \$\endgroup\$ – Wade Tyler Dec 31 '16 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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