잊혀진 영역 날짜 계산기 The Fading

날짜 라이브러리가 내장 된 언어와 언어가없는 언어 사이에서 경기장을 평준화하기 위해 가상의 달력으로 작업 해 봅시다. 잊혀진 영역은 ( ? 던전 앤 드래곤에 대한) 캠페인 설정. 물론 각자 고유 한 달력이 있습니다.

하프 토스의 달력

편리하게도 잊혀진 영역에서 1 년은 365 일입니다. 또한 달력에는 12 개월이 있습니다. 그러나 이것은 흥미로운 곳입니다. 매월 정확히 30 일입니다. 나머지 5 일은 해당 월 사이 의 공휴일입니다 . 다음은 순서대로 월과 공휴일입니다 (공휴일 들여 쓰기).

1   Deepwinter
        Midwinter
2   The Claw of Winter
3   The Claw of the Sunsets
4   The Claw of the Storms
        Greengrass
5   The Melting
6   The Time of Flowers
7   Summertide
        Midsummer
        [Shieldmeet]
8   Highsun
9   The Fading
        Highharvestide
10  Leaffall
11  The Rotting
        The Feast of the Moon
12  The Drawing Down

여섯 번째 휴일을 괄호 안에 넣었습니다. 이 날은 4 년마다 발생하는 비약의 날입니다. (그렇습니다. 수세기 동안 추가 세 나니가 없습니다).

월 이름에 대한 참고 사항 : 각 월에는 공식적인 이름과 공통 이름이 있습니다. 위의 일반적인 이름입니다. 나는 그들이 더 흥미로운 압축을 허용한다고 생각하기 때문에 그것들을 선택했습니다.

몇 년 동안 번호가 매겨졌지만 가장 널리 퍼져있는 것은 Dalereckoning 으로 DR로 단축되었습니다 . (또한 매년 하나 이상의 이름 이 있지만, 우리는 그것을 귀찮게하지 않을 것입니다.)

날짜의 구성 요소는 쉼표와 공백으로 구분해야합니다. 전체적으로 유효한 날짜는 다음과 같습니다.

4, The Melting, 1491 DR

또는

Shieldmeet, 1464 DR

휴일에는 요일 번호가 없습니다. (나는 4th of The Melting달 동안 더 좋을 것이라고 생각 하지만 서수를 이것으로 드래그하고 싶지 않습니다.)

각주 : xnor가 모든 단일 날짜 챌린지에 윤년 계산이 필요하다고 불평했을 때이 문제를 생각해 냈습니다. 나는 그것을 완전히 제거하는 데 실패했지만 적어도이 달력에서는 단일 모듈로 일뿐입니다.

도전

정수뿐만 아니라 Harptos 달력의 유효한 날짜가 주어지면 D날짜가 D며칠 후에 출력 됩니다. 참고 D사용자가 날짜를 반환해야하는 경우에있을 수 부정적 D일 이전합니다.

STDIN (또는 가장 가까운 대안), 명령 행 인수 또는 함수 인수를 통해 입력을 받고 STDOUT (또는 가장 가까운 대안), 함수 리턴 값 또는 함수 (out) 매개 변수를 통해 결과를 출력하는 프로그램 또는 함수를 작성할 수 있습니다.

연도가 긍정적이고 2000 미만이라고 가정 할 수 있습니다.

표준 규칙이 적용됩니다.

테스트 사례

첫 12 개 정도의 테스트 사례는 휴일과 윤년을 둘러싼 모든 주요 사례를 테스트해야합니다. 다음 세트는 여러 해에 걸친 작업 범위와 모든 월 및 휴일이 구현되었는지 테스트하는 것입니다. 후반은 모두 동일한 테스트 사례이지만 음수 오프셋입니다.

"30, Summertide, 1491 DR" 1                 => "Midsummer, 1491 DR"
"30, Summertide, 1491 DR" 2                 => "1, Highsun, 1491 DR"
"Midsummer, 1491 DR" 1                      => "1, Highsun, 1491 DR"
"30, Summertide, 1492 DR" 1                 => "Midsummer, 1492 DR"
"30, Summertide, 1492 DR" 2                 => "Shieldmeet, 1492 DR"
"30, Summertide, 1492 DR" 3                 => "1, Highsun, 1492 DR"
"Midsummer, 1492 DR" 1                      => "Shieldmeet, 1492 DR"
"Midsummer, 1492 DR" 2                      => "1, Highsun, 1492 DR"
"Shieldmeet, 1492 DR" 1                     => "1, Highsun, 1492 DR"
"1, Highsun, 1490 DR" 365                   => "1, Highsun, 1491 DR"
"1, Highsun, 1491 DR" 365                   => "Shieldmeet, 1492 DR"
"Shieldmeet, 1492 DR" 365                   => "Midsummer, 1493 DR"
"Midsummer, 1493 DR" 365                    => "Midsummer, 1494 DR"
"Shieldmeet, 1500 DR" 365                   => "Midsummer, 1501 DR"

"14, Deepwinter, 654 DR" 5069               => "The Feast of the Moon, 667 DR"
"Midwinter, 17 DR" 7897                     => "15, The Fading, 38 DR"
"3, The Claw of Winter, 1000 DR" 813        => "25, The Claw of the Storms, 1002 DR"
"Greengrass, 5 DR" 26246                    => "9, The Claw of the Sunsets, 77 DR"
"30, The Melting, 321 DR" 394               => "29, The Time of Flowers, 322 DR"
"17, The Time of Flowers, 867 DR" 13579     => "20, Highsun, 904 DR"
"Highharvestide, 1814 DR" 456               => "30, The Drawing Down, 1815 DR"
"23, The Rotting, 1814 DR" 3616             => "16, Leaffall, 1824 DR"
"1, Deepwinter, 1 DR" 730499                => "30, The Drawing Down, 2000 DR"

"Midsummer, 1491 DR" -1                     => "30, Summertide, 1491 DR"
"1, Highsun, 1491 DR" -2                    => "30, Summertide, 1491 DR"
"1, Highsun, 1491 DR" -1                    => "Midsummer, 1491 DR"
"Midsummer, 1492 DR" -1                     => "30, Summertide, 1492 DR"
"Shieldmeet, 1492 DR" -2                    => "30, Summertide, 1492 DR"
"1, Highsun, 1492 DR" -3                    => "30, Summertide, 1492 DR"
"Shieldmeet, 1492 DR" -1                    => "Midsummer, 1492 DR"
"1, Highsun, 1492 DR" -2                    => "Midsummer, 1492 DR"
"1, Highsun, 1492 DR" -1                    => "Shieldmeet, 1492 DR"
"1, Highsun, 1491 DR" -365                  => "1, Highsun, 1490 DR"
"Shieldmeet, 1492 DR" -365                  => "1, Highsun, 1491 DR"
"Midsummer, 1493 DR" -365                   => "Shieldmeet, 1492 DR"
"Midsummer, 1494 DR" -365                   => "Midsummer, 1493 DR"
"Midsummer, 1501 DR" -365                   => "Shieldmeet, 1500 DR"

"The Feast of the Moon, 667 DR" -5069       => "14, Deepwinter, 654 DR"
"15, The Fading, 38 DR" -7897               => "Midwinter, 17 DR"
"25, The Claw of the Storms, 1002 DR" -813  => "3, The Claw of Winter, 1000 DR"
"9, The Claw of the Sunsets, 77 DR" -26246  => "Greengrass, 5 DR"
"29, The Time of Flowers, 322 DR" -394      => "30, The Melting, 321 DR"
"20, Highsun, 904 DR" -13579                => "17, The Time of Flowers, 867 DR"
"30, The Drawing Down, 1815 DR" -456        => "Highharvestide, 1814 DR"
"16, Leaffall, 1824 DR" -3616               => "23, The Rotting, 1814 DR"
"30, The Drawing Down, 2000 DR" -730499     => "1, Deepwinter, 1 DR"



답변

루비 543 523 521 498 511 509 바이트

이 질문에 대한 더 많은 답변을 장려하기 위해 루비 버전의 Python 답변을 게시 할 예정입니다. 이 답변 더 짧지 만 별로는 아닙니다. 수 당신은 잘 할?

편집 : Martin Büttner 덕분에 그의 제안을 여기에 .

편집 : 나는 “한 달에 일 수”목록을 상당히 아래로 골프.

편집 : 내가 처리하는 방법을 아래로 골프 반면 d[10]=r%4<1?1:0d[10]=0**(r%4) 바이트, 나는 아래로 골프를하는 동안 버그를 도입했던 발견 dShieldmeet 실수로 30 일이 있었다 그래서, 일 목록의 수를. 따라서 바이트 수가 다시 증가했습니다. 또한이 버그를 수정하기 위해 Python 답변을 편집 할 것입니다.

편집하다: 이 질문에서 함수의 이름을 지정할 필요가 없다는 것을 잊었습니다.

->s,n{x=s[0..-4].split(", ");x=x[2]?x:[1,*x];t=(["Deepwinter,Midwinter","Winter","Sunsets","the Storms,Greengrass,The Melting,The Time of Flowers,Summertide,Midsummer,Shieldmeet,Highsun,The Fading,Highharvestide,Leaffall,The Rotting,The Feast of the Moon,The Drawing Down"]*',The Claw of ').split(?,);p,q,r=x[0].to_i+n,t.index(x[1]),x[2].to_i;d=[30,1,30,30]*4+[1,30];d[10]=0**(r%4);(a=p<1?1:-1;q=(q-a)%18;p+=a*d[a<0?q-1:q];r-=a*0**q;d[10]=0**(r%4))until(1..d[q])===p;z=d[q]<2?[t[q],r]:[p,t[q],r];z*", "+" DR"}

언 골프 드 :

def h(s,n)
  x=s[0..-4].split(", ")
  x=x[2]?x:[1,*x]
  t=["Deepwinter,Midwinter","Winter","Sunsets","the Storms,Greengrass,The Melting,The Time of Flowers,Summertide,Midsummer,Shieldmeet,Highsun,The Fading,Highharvestide,Leaffall,The Rotting,The Feast of the Moon,The Drawing Down"]
  t=t*',The Claw of '           # turns the above array into a string with "Claw"s inserted
  t=t.split(?,)                 # then splits that string back up again by ","
  p=x[0].to_i+n
  q=t.index(x[1])
  r=x[2].to_i
  d=[30,1,30,30]*4+[1,30]
  d[10]=0**(r%4)
  until(1..d[q])===p
    a=p<1?1:-1
    q=(q-a)%18
    p+=a*d[a<0?q-1:q]
    r-=a*0**q
    d[10]=0**(r%4)
  end
  z=d[q]<2?[t[q],r]:[p,t[q],r]  # putting z=[t[q],r] on another line saved me no bytes
  z*", "+" DR"
end


답변

파이썬 3 712 652 636 567 563 552 550 548 529 540 바이트

마침내 나는이 훌륭한 질문에 대한 답을 쓸 시간을 찾았습니다. 아직 골프를 치고 있지는 않습니다 (이 경우 월 이름 목록 과 일 수 목록 은 특히 ​​심각 합니다. 음수를 처리 D하려면 별도의 while 루프가 필요합니다 ) 적어도 대답입니다.

편집 : 버그 수정

def h(s,n):
 x=s[:-3].split(", ");x=[1]*(len(x)<3)+x;t="Deepwinter,Midwinter,The Claw of Winter,The Claw of the Sunsets,The Claw of the Storms,Greengrass,The Melting,The Time of Flowers,Summertide,Midsummer,Shieldmeet,Highsun,The Fading,Highharvestide,Leaffall,The Rotting,The Feast of the Moon,The Drawing Down".split(",");p,q,r=int(x[0])+n,t.index(x[1]),int(x[2]);d=[30,1,30,30]*4+[1,30];d[10]=r%4<1
 while p>d[q]or p<1:a=[-1,1][p<1];q=(q-a)%18;p+=a*d[q-(a<0)];r-=a*0**q;d[10]=r%4<1
 return', '.join([str(p)]*(d[q]>2)+[t[q],str(r)])+" DR"

언 골프 드 :

def harptos(date, num):
    t = "Deepwinter,Midwinter,The Claw of Winter,The Claw of the Sunsets,The Claw of the Storms,Greengrass,The Melting,The Time of Flowers,Summertide,Midsummer,Shieldmeet,Highsun,The Fading,Highharvestide,Leaffall,The Rotting,The Feast of the Moon,The Drawing Down"
    t = t.split(",")        # split up the names of the months
    x = date[:-3]           # removes " DR"
    x = x.split(", ")
    if len(x) < 3:
        x = [1] + x         # if we have two items (holiday), append a "day of the month"
    p = int(x[0]) + num     # initialize the "date" by adding num to it
    q = t.index(x[1])
    r = int(x[2])
    d=[30,1,30,30]*4+[1,30] # all the month lengths
    d[10] = r%4 < 1         # leap year toggle
    while p > d[q]:         # while the "date" > the number of days in the current month
        p -= d[q]           # decrement by number of days in current month
        q = (q+1)%18        # increment month
        r += 0**q           # increment year if the incremented month == the first month
        d[10] = r%4 < 1     # leap year toggle
    while p < 1:            # while the "date" is negative
        q = (q-1)%18        # decrement month first
        p += d[q]           # add the number of days in the decremented month
        r -= 0**q            # decrement year if the decremented month == the first month
        d[10] = r%4 < 1     # leap year toggle
    m = [t[q],str(r)]       # start the result array
    if d[q] > 2:
        m = [str(p)] + m    # if the month is NOT a holiday, add the day
    return ", ".join(m) + " DR"


답변