首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pi日,Pi分钟,还是Pi秒?

Pi日,Pi分钟,还是Pi秒?
EN

Code Golf用户
提问于 2016-01-02 01:01:09
回答 7查看 1.8K关注 0票数 19

在这个挑战中,您需要确定是Pi日、Pi分钟还是Pi秒。

因为Pi是不合理的,所以它希望您的代码尽可能短。

示例

不提供输入,您的程序应该使用系统时间。我只是为了清楚地加入了它

代码语言:javascript
复制
March 14, 2016 0:00:00
Pi Day
December 25, 2015 3:14:45
Pi Minute
December 29, 2015 0:03:14
Pi Second
January 1, 2016 0:00:00
<No Output>

什么是Pi日/分钟/秒

  • Pi Day是三月的月份,而日期是十四号
  • Pi Minute是当时间是3,分钟是14。
  • Pi Second是当分钟是3,第二个是14
  • Pi Day应该是首选而不是Pi MinutePi Second,而Pi Minute应该是首选而不是Pi Second
  • 对于这个挑战,你应该使用12小时的时间(15:14 == 3:14).用于确定Pi Day/Minute/Second的日期/时间应基于系统时间。

计分加奖金

-15字节加值:如果您在没有Pi时间的情况下打印"No Pi Time"

和往常一样,标准漏洞是不允许的。这是密码-高尔夫最短的字节代码赢!

EN

回答 7

Code Golf用户

回答已采纳

发布于 2016-01-02 10:07:03

CJam,41字节

代码语言:javascript
复制
et[3E]#"
Pi Day

Pi Minute
Pi Second
"N/=

在这里测试一下。或者使用此链接来存根et的结果,以便更容易地进行测试。

解释

代码语言:javascript
复制
et   e# Get the current datetime as an array with the following elements:
     e#   - Year
     e#   - Month
     e#   - Day
     e#   - Hour
     e#   - Minute
     e#   - Second
     e#   - Millisecond
     e#   - Weekday
     e#   - Tickrate or something.
[3E] e# Push the array [3 14].
#    e# Find the position of this subarray in the current datetime array. Let's see
     e# what results we can get:
     e#   - Year 3 is in the past and there is no 14th month, so we can't get 0.
     e#   - Pi day will give result 1.
     e#   - Day 3, hour 14 would give 2.
     e#   - Pi minute will give result 3.
     e#   - Pi second will give result 4.
     e#   - Second 3, millisecond 14 would give 5.
     e#   - Weekday and tickrate won't be 14, so we'll never get 6 or 7.
     e#   - If [3 14] isn't found at all we get -1.
"\Pi Day\\Pi Minute\Pi Second\"
     e# Push this string (with linefeeds instead of backslashes.
N/   e# Split into lines.
=    e# Select the corresponding element. The non-existent "pi hour" and "pi millisecond"
     e# would map to empty strings as well as the -1.
票数 4
EN

Code Golf用户

发布于 2016-01-02 14:13:55

Japt,78 - 15 = 63字节

代码语言:javascript
复制
D=Ð)g ¥3©Df ¥E?"Pi Day":Dd %C¥3©Dc ¥E?`Pi M©e`:Dc ¥3©Db ¥E?`Pi SeÖ:No Pi Te

很直截了当-检查每一件案子的日期。

解释:

  • D=Ð)g获取当前日期(Ð),将其存储在变量D中,并获取月份(g)。如果它已经是一个字母,为什么要把它存储在变量中呢?因为从那时起,您可以使用Da来修饰日期的任何部分,其中a是函数,返回年份、月份、日期等。但是,否则您必须做Ð a,查看空格。
  • ¥3==3,检查月份是否是3月。
  • ©&&,即"and“。
  • Df是一个月中的一天。
  • E是14岁
  • ?...:... -三值算子的典型集
  • Dd %C提醒将小时(Dd)除以12 (C)
  • Dc是分钟
  • Db是秒

在网上试试!

为了模仿Pi日:

代码语言:javascript
复制
D=Ð"3/14/11 11:11:11";
Dg ¥2©Df ¥E?"Pi Day":Dd %C¥3©Dc ¥E?`Pi M©e`:Dc ¥3©Db ¥E?`Pi SeÖ:No Pi Te

模仿Pi分钟

代码语言:javascript
复制
D=Ð"11/11/11 3:14:11";
Dg ¥2©Df ¥E?"Pi Day":Dd %C¥3©Dc ¥E?`Pi M©e`:Dc ¥3©Db ¥E?`Pi SeÖ:No Pi Te

模仿Pi秒

代码语言:javascript
复制
D=Ð"11/11/11 00:3:14";
Dg ¥2©Df ¥E?"Pi Day":Dd %C¥3©Dc ¥E?`Pi M©e`:Dc ¥3©Db ¥E?`Pi SeÖ:No Pi Te
票数 4
EN

Code Golf用户

发布于 2016-01-02 01:26:51

TI-BASIC,124个字节

感谢FlagAsSpam剃了几个字节。

代码语言:javascript
复制
"→Str1
getTime
If min({3,14}={Ans(2),Ans(3
"Pi Second→Str1
getTime
If Ans(2)=14 and max(Ans(1)={3,14
"Pi Minute→Str1
getDate
If min({3,14}={Ans(2),Ans(3)
"Pi Day→Str1
Str1
票数 3
EN
页面原文内容由Code Golf提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://codegolf.stackexchange.com/questions/68371

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档