日付ライブラリが組み込まれている言語と組み込まれていない言語の間で競争の場を平準化するために、架空のカレンダーを使用してみましょう。Forgotten Realmsは、Dungeons&Dragonsの(the?)キャンペーン設定です。もちろん、それぞれに独自のカレンダーがあります。
ハプトスのカレンダー
便利なことに、忘れられた領域の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
括弧内に6番目の休日を挿入したことに注意してください。これは4年ごとにのみ発生するうるう日です(はい、そうです-何世紀にもわたって追加のシェナンガンはありません)。
月の名前に関する補足事項:各月には正式名と共通名があります。上記は一般的な名前です。それらを選んだのは、それらがより興味深い圧縮を可能にしていると思うからです。
年の番号付けはいくつかありますが、最も普及しているのはDRに短縮されたDalereckoningです。(また、毎年1つ以上の名前がありますが、それを気にするつもりはありません。)
日付の構成要素は、コンマとスペースで区切る必要があります。全体として、有効な日付は次のようになります。
4, The Melting, 1491 DR
または
Shieldmeet, 1464 DR
休日には日番号がないことに注意してください。(4th of The Melting
月の数日間はもっといいと思うが、序数をこの中にドラッグしたくない。)
脚注:日付のすべてのチャレンジにうるう年の計算が必要であるとxnorが不平を言ったとき、私はこれを思いつきました。私はそれを完全に削除することに失敗しましたが、少なくともこのカレンダーではモジュロは1つだけです。
チャレンジ
Harptosのカレンダーの有効な日付と整数を指定するD
と、日付をD
数日後に出力します。D
負の値になる可能性があることに注意してください。その場合は、日付をD
早めに返す必要があります。
プログラムまたは関数を作成し、STDIN(または最も近い代替)、コマンドライン引数または関数引数を介して入力を取得し、STDOUT(または最も近い代替)、関数の戻り値または関数(out)パラメーターを介して結果を出力できます。
年は正で2000年未満であると仮定できます。
標準のコードゴルフ規則が適用されます。
テストケース
最初の数十件のテストケースは、休日とうるう年を取り巻くすべてのエッジケースをテストする必要があります。次のセットでは、複数年にわたる作業の範囲をテストし、すべての月と休日を実装します。後半もまた同じテストケースですが、負のオフセットがあります。
"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"