2017 is Almost Here!

17

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

Quantum spaghettification

Posted 2016-12-31T10:05:09.843

Reputation: 273

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 – 2016-12-31T10:08:59.980

@GregMartin See my edit for clarification. – Quantum spaghettification – 2016-12-31T10:10:12.440

What should happen if I run the program on 3 January? – betseg – 2016-12-31T10:16:13.817

@betseg ye I just thought about that to. See edit :). It should work the same even though the output will be large. – Quantum spaghettification – 2016-12-31T10:18:56.640

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 – 2016-12-31T10:23:51.443

@edc65 Yep so if you are 45mins from 0:00:00 you should output 1 times if 43hours 15 mins you should output 44 times – Quantum spaghettification – 2016-12-31T10:27:01.070

@Quantumspaghettification What about on 0:00:00 of Jan, it should output nothing? – Gurupad Mamadapur – 2016-12-31T14:04:37.647

@GurupadMamadapur I will leave that open, but I very much doubt that any output at 0:00:00 will be seen since it is only that time for one second (at the most). – Quantum spaghettification – 2016-12-31T16:57:23.380

@Quantumspaghettification Ok great thanks. I'll output 2017 once because it saves bytes :) – Gurupad Mamadapur – 2016-12-31T17:13:33.850

I noticed bits are specified, not bytes. I sense an incoming solution in 7 with an argument in comments about scoring. – Pavel – 2016-12-31T22:31:56.500

Hey, can you please update the correct answer? – Gurupad Mamadapur – 2018-03-16T11:48:04.023

Answers

6

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>

edc65

Posted 2016-12-31T10:05:09.843

Reputation: 31 086

4

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.

Gurupad Mamadapur

Posted 2016-12-31T10:05:09.843

Reputation: 1 791

@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 – 2016-12-31T14:09:49.367

3

Pyth - 71 68 bytes

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

Uses the same logic used in my python 3.5 answer.

Try it here!

Gurupad Mamadapur

Posted 2016-12-31T10:05:09.843

Reputation: 1 791

@Quantumspaghettification Isn't this shorter? – Gurupad Mamadapur – 2017-01-15T22:24:50.340

2

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.

Wade Tyler

Posted 2016-12-31T10:05:09.843

Reputation: 261

Aren't you able to do n.tm_hour=n.tm_min=...=n.tm_mon=0;? – LegionMammal978 – 2016-12-31T13:43:57.923

@LegionMammal978 Oh yeah, I forgot. Thanks. – Wade Tyler – 2016-12-31T14:39:01.140