2017快到了!


17

挑战

挑战很简单:

不输入任何内容并输出以下消息:

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

此次数等于2016年12月31日午夜UTC之前或之后的小时数。

例子

例如,如果它是12月31日19:01 UTC,则应输出:

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

如果是12月31日世界标准时间23:24,则应输出:

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

如果是1月42日UTC 1月1日,则应输出:

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

澄清:如果是12月31日晚上10-11点,则应输出两个,12月31日晚上11-12点输出一个,1月1日上午1月1日输出一个,1月1日上午02日2月1日输出两个,依此类推。

规则

  • 无输入
  • 尾随行或空格都可以。
  • 您的程序应该在我运行它的任何时间或一天运行(尽管输出很大)。例如,在1月2日凌晨00:15,您的代码应输出25次。

(这是我对Code Golf的第一个问题,因此,如果我有任何重要的事情遗漏,请告诉我。)

这是Code Golf,所以最短的胜利


小时数是否舍入到最接近的整数?如果在新年午夜半小时内,是否没有输出?
格雷格·马丁

@GregMartin参阅我的编辑以进行澄清。
量子面条化

如果我在1月3日运行该程序,该怎么办?
betseg '16

@betseg是的,我刚刚想到了这个。参见编辑:)。即使输出很大,它也应该工作相同。
量子面条化

不错的第一个问题。关于四舍五入:重复次数是当前时间UCT与1月1日UTC的0:00:00之间的差的绝对值,四舍五入。正确?
edc65 '16

Answers:


6

JavaScript(ES6),107

作为没有参数的匿名方法

注意1483228800000Date.UTC(2017,0)

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

测试这会每1分钟更新一次,但您需要耐心等待才能看到输出变化。

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

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

setInterval(update,60000)

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


4

Python 2-97 + 17 = 114字节

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

edc65的答案中借来上限的逻辑。

Python 3.5-116字节

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

math.ceil在中返回整数,3.x而在2.x其中返回浮点数。

感谢elpedro节省了3个字节。


@ElPedro谢谢。打算这样做,在我以前的解决方案中,我在弄混datetime.now(pytz.utc).timestamp()需要python 3.5的东西。
Gurupad Mamadapur


2

用Clang 3.8.1编译的C 327 317 145字节

@ edc65节省了172个字节

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

不打高尔夫球

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

t=difftime(t, 1483228800)/3600;

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

317字节

@ LegionMammal978节省了10个字节

#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");

不打高尔夫球

#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");
}

我将在可能的时候添加一些解释。


你不能做 n.tm_hour=n.tm_min=...=n.tm_mon=0;吗?
LegionMammal978'2013/

@ LegionMammal978哦,是的,我忘了。谢谢。
韦德·泰勒
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.