Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
    
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? – Greg Martin 12 hours ago
    
@GregMartin See my edit for clarification. – Quantum spaghettification 12 hours ago
    
What should happen if I run the program on 3 January? – betseg 12 hours ago
    
@betseg ye I just thought about that to. See edit :). It should work the same even though the output will be large. – Quantum spaghettification 12 hours ago
    
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? – edc65 12 hours ago

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>

share|improve this answer

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.

share|improve this answer
    
You posted my solution just before I did ;-) You can save 2 bytes by labeling it Python 2 and removing the brackets from the print. – ElPedro 8 hours ago
    
@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. – Gurupad Mamadapur 8 hours ago
    
Also print'_ __ __\n | | | | |\n |_ |__| | |\n'*int(... takes it down to 103 in Python 2. – ElPedro 8 hours ago

C compiled with Clang 3.8.1 327 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.

share|improve this answer
    
Aren't you able to do n.tm_hour=n.tm_min=...=n.tm_mon=0;? – LegionMammal978 9 hours ago
    
@LegionMammal978 Oh yeah, I forgot. Thanks. – Wade Tyler 8 hours ago

Pyth - 71 bytes

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

Uses the same logic used in my python 3.5 answer.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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