Nel tentativo di livellare il campo di gioco tra le lingue con librerie di date integrate e quelle senza, lavoriamo con un calendario immaginario. The Forgotten Realms sono un'impostazione della campagna ( la? ) Per Dungeons & Dragons. Naturalmente, ognuno ha il proprio calendario.
Il calendario di Harptos
Convenientemente, un anno nei Reami dimenticati ha anche 365 giorni. Inoltre, il calendario ha anche 12 mesi. Tuttavia, è qui che diventa interessante. Ogni mese dura esattamente 30 giorni. I restanti 5 giorni sono festivi che cadono tra i mesi. Ecco i mesi e le festività in ordine (con festività rientrate):
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
Si noti che ho inserito una sesta vacanza tra parentesi. Questo è il giorno bisestile che si verifica solo ogni quattro anni (sì, è così - non ci sono altri shenanigani con i secoli).
Nota a margine sui nomi dei mesi: ogni mese ha un nome formale e un nome comune. Quanto sopra sono i nomi comuni. Ho scelto quelli perché penso che consentano una compressione più interessante.
Ci sono diverse numerazioni degli anni, ma la più diffusa è Dalereckoning , abbreviata in DR . (Inoltre, ogni anno ha uno o più nomi , ma non ci preoccuperemo.)
I componenti di una data devono essere separati da una virgola e uno spazio. Tutto sommato, una data valida potrebbe apparire come:
4, The Melting, 1491 DR
o
Shieldmeet, 1464 DR
Si noti che non esiste un numero di giorno per le festività. (Suppongo che 4th of The Meltingsarebbe meglio per i giorni dei mesi, ma non voglio trascinare i numeri ordinali in questo.)
Nota a piè di pagina: mi sono inventato questo quando xnor si è lamentato del fatto che ogni singola sfida con le date ha bisogno del calcolo dell'anno bisestile. Non sono riuscito a eliminarlo completamente, ma almeno è solo un singolo modulo in questo calendario.
La sfida
Data una data valida del Calendario di Harptos, nonché un numero intero D, restituisce la data Dgiorni dopo. Si noti che Dpotrebbe essere negativo, nel qual caso è necessario restituire la data Dgiorni prima.
È possibile scrivere un programma o una funzione, prendendo l'input tramite STDIN (o l'alternativa più vicina), l'argomento della riga di comando o l'argomento della funzione e producendo il risultato tramite STDOUT (o l'alternativa più vicina), il valore di ritorno della funzione o il parametro della funzione (out).
Si può presumere che l'anno sia positivo e inferiore a 2000.
Si applicano le regole standard del code-golf .
Casi test
La prima dozzina di casi di test dovrebbe testare tutti i casi limite che circondano le vacanze e gli anni bisestili. Il prossimo set è quello di testare che si estende su più anni di lavoro e tutti i mesi e le vacanze sono stati implementati. La seconda metà è di nuovo tutti gli stessi casi di test ma con offset negativi.
"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"