过去的今天


15

所述Discordian日历是由Discordians使用的备选的日历。

  1. Discordian年有5个季节,每个季节持续73天:混乱,不和谐,混乱,官僚主义和余波。
  2. Discordian星期有5天:Sweetmorn,Boomtime,Pungenday,Prickle-Prickle和Setting Orange。每年从Sweetmorn(以及Chaos)开始。
  3. ˚F ourth年(其中Happe的ñ s到格雷格对准Ø日安飞跃啊[R S),一个额外d AY插入混沌59和60混沌之间称为圣提布节。它不在Discordian周内,这意味着St. Tib's Day之后的第二天将设置为Orange,即Prickle-Prickle的前一天。
  4. 公历和Discordian日历排成一行;两者都在同一天开始,在公历中是1月1日,在Discordian中是1。
  5. 圣母不和谐元年(YOLD 1)是公历前1166年,公历前一年,意味着今年(2017 AD)为YOLD 3183。
  6. Discordian日历也有假期,但是对于这一挑战而言,假期并不重要,因此您不应输出它们或有关它们的任何内容。

编写一个程序或函数以输出或返回今天的日期(在执行时):

Today is Boomtime, the 16th day of Confusion in the YOLD 3183

格式为"Today is $day_of_the_week, the $ordinal day of $season in the YOLD $year",其中$ day_of_the_week是大写的星期几(标题大小写),$ ordinal是本赛季的第几天(第1、2nd,3rd,4th等),$ season是大写的日期(标题大小写)季节,而$ year是年份。

如果您的程序或函数在圣提比纪念日执行,则应改为输出或返回"Today is St. Tib's Day in the YOLD $year"

规则:

  • 有标准漏洞。
  • 如果您选择的语言无法获取当前日期,则它也可以采用任何合理格式的当前公历日期作为输入。
  • 这是,最短的代码(每种语言)获胜。
  • 尾随空格是可以的。
  • 资本化问题。
  • ddate禁止以任何方式拨打电话
  • 您的程序应保证能在3067到3265 YOLD(1901到2099 AD)之间工作,超出该范围它可能会给出错误的值

也可以看看:


4
discord是一个很棒的即时消息客户端
Okx

1
我认为今天是混乱的第16天?该示例代表什么日期?
user202729


1
@ user202729是的,示例中的日期是我最初编写挑战的日期,我将对其进行更新以显示今天的日期,这实际上是混乱的第16天。
L3viathan

1
@ L3viathan在这种情况下(对于那些使用具有较大本机类型的语言的用户),您可以澄清一下吗?与“与格里高利主义者保持一致” b)如何在引入格里高利校准之前处理几年。我建议的最大范围由您当前的规格正确定义。如果您拒绝此操作,则应定义该程序在该范围之外应执行的操作。另外,您应该避免使现有答案无效。en.wikipedia.org/wiki/Gregorian_calendar
Level River St St

Answers:


5

Mathematica,403401字节

用于计数字节数的版本:(删除的空格和换行符-不幸的是,这部分很难

"Setting Orange"["Sweetmorn","Boomtime","Pungenday","Prickle-Prickle"][[#~Mod~5]]<>", the "<>SpokenString@p[[Mod[#,73,1]]]~StringExtract~2<>" day of "<>{"Chaos","Discord","Confusion","Bureaucracy","The Aftermath"}[[⌈#/73⌉]]&;
Row@{"Today is ",#2," in the YOLD ",1166+#}&[#,If[4∣#,If[#2>60,%[#2-1],If[#2<60,%@#2,"St.Tib's Day"]],%@#2]]&@@FromDigits/@DateString@"ISOOrdinalDate"~StringSplit~"-"

要阅读的版本:

"Setting Orange"["Sweetmorn", "Boomtime", "Pungenday", 
     "Prickle-Prickle"][[#~Mod~5]] <>
   ", the " <>
   SpokenString@p[[Mod[#, 73, 1]]]~StringExtract~2 <>
   " day of " <>
   {"Chaos", "Discord", "Confusion", "Bureaucracy", 
     "The Aftermath"}[[Ceiling[#/73]]] &;
Row@{
      "Today is ",
      #2,
      " in the YOLD ",
      1166 + #
      } &[#,
   If[4 ∣ #,
    If[#2 > 60, %[#2 - 1],
     If[#2 < 60, %@#2, "St.Tib's Day"]
     ], %@#2
    ]] & @@ FromDigits /@ DateString@"ISOOrdinalDate"~StringSplit~"-"

通过用替换为,并用数字替换DateString@"ISOOrdinalDate",可以用任意日期测试答案。DateString[{year,month,day},"ISOOrdinalDate"]yearmonthday


如何测试Mathematica代码?
L3viathan

6
“没有内置的功能吗?”
乔纳森·艾伦

4

Python 2,423字节

精简版:

import time
y,d=time.gmtime()[0::7]
t="Today is "
o=" in the YOLD "+`y+1166`
if y%4<1 and d>59:
 if d==60:print"%sSt. Tib's Day%s%d"%(t,o);quit()
 d-=1
s,e=divmod(d-1,73)
print t+["Sweetmorn","Boomtime","Pungenday","Prickle-Prickle","Setting Orange"][(d-1)%5]+", the %d%s day of %s"%(e+1,'tsnrthtddh'[min(e*(e/10-1 and 1)%10,4)::5],["Chaos","Discord","Confusion","Bureaucracy","The Aftermath"][s]+o)

更长,更易读的形式:

import time

# now = time.strptime("2017.06.11", "%Y.%m.%d")  # for testing
now = time.gmtime()
year, day_of_year = now[0::7]
leapyear = year % 4 < 1
today = "Today is "
yold = " in the YOLD " + `y+1166`

if leapyear and day_of_year>59:
    if day_of_year==60:
        print "%sSt. Tib's Day%s%d"% (today, yold)
        quit()  # dirty, but ... hey.
    day_of_year -= 1
season, day = divmod(day_of_year-1,73)

print today + \
    ["Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange"][(day_of_year-1)%5] + \
    ", the %d%s day of %s" % (
        day+1,
        'tsnrthtddh'[min(day*(day/10-1 and 1)%10,4)::5],
        ["Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"][season] + yold
    )

更新:在出色的@Neil和@EriktheOutgolfer的帮助下修复。但是@Jonathans的答案要短得多。


2
欢迎参加编程难题和代码高尔夫球!
达达(Dada)

3
这样会为21st,22nd,23rd ... 73rd生成正确的后缀吗?@ L3viathan y%4<1可以工作,但我认为1-y%4不会。
尼尔


@EriktheOutgolfer您不能通过消除e变量来节省另外4个字节吗?
尼尔

欢迎来到PPCG!不错的第一篇文章。我本来打算给您一些零散的信息,但是却发现并解决了后缀问题,并且比我想的要多,所以我最终提交了自己的版本。
乔纳森·艾伦,

2

Python 2 346字节

注意:这是对Jammon的回答的高尔夫(和修正)-我本来以为我要发表评论,但是最后我做了很大的改变(加上后缀已固定)。

import time
y,d=time.gmtime()[::7]
t="Today is %s in the YOLD "+`y+1166`
r=y%4<1<59<d
d-=r+1
e=d%73
print t%[["Sweetmorn","Boomtime","Pungenday","Prickle-Prickle","Setting Orange"][d%5]+", the %d%s day of "%(e+1,'snrttddh'[min(e%10+3*(e/9==1),3)::4])+["Chaos","Discord","Confusion","Bureaucracy","The Aftermath"][d/73],"St. Tib's Day"][(r*d)==58]

在线尝试!或查看一些硬编码的测试日期


我不认为e%10*(e/9!=1)行得通吗?
尼尔

不,那么它会打印11st12st13st(当e/9为1它被零将乘法和min将挑选零)
乔纳森艾伦

2

JavaScript(ES6),387 380字节

f=(d=new Date(),a=d.getDate()-1,y=d.getFullYear()+1166)=>d.getMonth()?f(d,a+d.getDate(d.setDate(0))):`Today is ${y%4-2|a<59||59-a--?`Sweetmorn,Boomtime,Pungenday,Prickle-Prickle,Setting Orange`.split`,`[a%5]+`, the ${d=a%73+1}${[,`st`,`nd`,`rd`][d-10-(d%=10)&&d]||`th`} day of `+`Chaos,Discord,Confusion,Bureaucracy,The Aftermath`.split`,`[a/73|0]:`St. Tib's Day`} in the YOLD `+y

采用可选的date参数。取消高尔夫:

function discordian(date) {
    var a = date.getDate();
    while (date.getMonth()) {
        date.setDate(0);
        a += date.getDate();
    }
    if (date.getYear() % 4 == 0) {
        if (a == 60) return "Today is St. Tib's day in the YOLD " + (date.getYear() + 1166);
        if (a > 60) a--;
    }
    var weekday = ['Setting Orange', 'Sweetmorn', 'Boomtime', 'Pungenday', 'Prickle-Prickle'][a % 5];
    var seasonday = (a - 1) % 73 + 1;
    var ordinal = seasonday % 10 == 1 && seasonday != 11 ? 'st' : seasonday % 10 == 2 && seasonday != '12' : 'nd' : seasonday % 10 == 3 && seasonday != '13' ? 'rd' : 'th';
    var season = ['Chaos', 'Discord', 'Confusion', 'Bureaucracy', 'The Aftermath'][Math.floor((a - 1) / 73)];
    return "Today is " + weekday + ", the " + seasonday + ordinal + " day of " + season + " in the YOLD " + (date.getYear() + 1166);
}

1

C#,392个字节

using System;s=>{var t=DateTime.Now;int d=t.DayOfYear,y=t.Year,m=d%73;return"Today is "+(DateTime.IsLeapYear(y)&d==60?"St. Tib's Day":"Sweetmorn|Boomtime|Pungenday|Prickle-Prickle|Setting Orange".Split('|')[d%5-1]+", the "+ m+(m<2|m==21|m>30?"st":m==2|m==22?"nd":m==3|m==23?"rd":"th")+" day of "+"Chaos|Discord|Confusion|Bureaucracy|The Aftermath".Split('|')[d/73])+" in the YOLD "+(y+1166);}

完整/格式化版本:

using System;

class P
{
    static void Main()
    {
        Func<string, string> f = s =>
        {
            var t = DateTime.Now;
            int d = t.DayOfYear, y = t.Year, m = d % 73;

            return "Today is " + (DateTime.IsLeapYear(y) & d == 60
                   ? "St. Tib's Day"
                   : "Sweetmorn|Boomtime|Pungenday|Prickle-Prickle|Setting Orange".Split('|')[d % 5 - 1] +
                     ", the " +
                     m +
                     (m < 2 | m == 21 | m > 30 ? "st" : m == 2 | m == 22 ? "nd" : m == 3 | m == 23 ? "rd" : "th") +
                     " day of " +
                     "Chaos|Discord|Confusion|Bureaucracy|The Aftermath".Split('|')[d / 73])
                   + " in the YOLD " + (y + 1166);
        };

        Console.WriteLine(f(null));

        Console.ReadLine();
    }
}

1

Pyth,295字节

J.d2A<J2Kt+s<+,31 28*2t*3,30 31tH@J2=Y&&!%G4<58K!qH3=N%K73%"Today is %s in the YOLD %d",@,++@c"SweetmornZBoomtimeZPungendayZPrickle-PrickleZSetting Orange"\Z%K5%", the %d%s day of ",+N1@c"stndrdth"2h.mb,3+%NT*3q1/N9@c." yNlSFk.»&ô?Z#u!%ô6'mçM«_ôvëû¹)+¬<"\Z/K73"St. Tib's Day"q*YK59+G1166

注意:包含二进制文件,从此处复制粘贴可能并不安全。从TIO复制粘贴应该起作用。

在线尝试!

您可以通过.d2在开头用3元组(年,月,日)替换开头来测试任意日期,如下所示:(2020 2 29)

因为Pyth无法获得“一年中的某天”,所以这一点有些烦人,所以我必须自己计算。

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.