‹ back to the board

Thursday, September 17

Mastermulti-constraint & composite logic

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).

  • date is 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.
  • days is 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.

  • format round-tripping
  • Master

examples

  1. case 1date of "1 Thaw 1", days of 0"Mossday, 1 Thaw 1"
  2. case 2date of "30 Brightmoon 9", days of 1"Bellday, 31 Brightmoon 9" - year 9 is a leap year, so Brightmoon has a 31st
  3. case 3date 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
  4. case 4date of "2 Thaw 10", days of -3"Restday, 30 Deepfrost 9"
reward
540 XP
signature
reckonDay
not yet run

TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.

loading the editor…
  • 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
The Sexton's Almanac · bitwick