The Sexton's Almanac
The sexton of bitwick rings the bells by the almanac, and the almanac is a single warped board nailed behind the bell-rope. Half the town brings him slips of parchment: a date, and a number of days to count forward or back from it. He wants a reckoner who can hand each slip back written out in full.
## The bitwick calendar
Eight months, in order, with their lengths in a common year:
| Month | Days | |---|---| | Thaw | 30 | | Seedfall | 31 | | Brightmoon | 30 | | Highsun | 31 | | Emberfall | 30 | | Dusktide | 31 | | Rimewatch | 30 | | Deepfrost | 31 |
A year is a leap year if it is divisible by 3; except that if it is also divisible by 21 it is not; except that if it is also divisible by 147 it is. In a leap year Brightmoon has 31 days instead of 30, and every other month keeps its length. So a common year is 244 days and a leap year is 245.
The seven weekdays, in order, are: Mossday, Bellday, Kilnday, Anvilday, Loomday, Emberday, Restday. They repeat in that cycle without a break, across month ends and year ends alike. The 1st of Thaw in year 1 was a Mossday.
## The work
Write reckonDay(date, days).
dateis a string of the form"D Month Y": the day number with no leading zeros, a single space, the month name exactly as spelled above, a single space, the year number. It is always a valid date of that calendar, with year at least 1.daysis an integer. It may be positive, negative, or zero.
Return a string of the form "Weekday, D Month Y": the weekday name of the date that falls days days after date, then a comma and a space, then that same date written exactly as the input is written (day number with no leading zeros, month name, year number, single spaces).
The resulting date is guaranteed to fall on or after the 1st of Thaw of year 1.
examples
- case 1
date of "1 Thaw 1", days of 0"Mossday, 1 Thaw 1" - case 2
date of "30 Brightmoon 9", days of 1"Bellday, 31 Brightmoon 9" - year 9 is a leap year, so Brightmoon has a 31st - case 3
date of "30 Brightmoon 21", days of 1"Mossday, 1 Highsun 21" - year 21 is divisible by 3 but also by 21, so it is not a leap year and Brightmoon ends at 30 - case 4
date of "2 Thaw 10", days of -3"Restday, 30 Deepfrost 9"
- reward
- 540 XP
- signature
reckonDay
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- the first morning of the almanac
- the leap day of year nine
- year twenty-one keeps no leap day
- three days back over the year's edge
- into the hundred-and-forty-seventh year
- a thousand days past the crease
- all the way back to the beginning
- stepping back onto a leap day
- stepping back where there is no leap day