‹ back to the board

Sunday, October 18

Mastermulti-constraint & composite logic

The Cove-Writs of Corrigal Sound

The Admiralty of Corrigal Sound licenses its privateers by writ. Each writ opens or shuts the hidden coves of the Sound to a ship, and over many seasons the writs have piled up, overruled and struck out one another. The Corsairs' Compact will pay a reckoner who can tell any captain, before the tide turns, whether a given cove is open to their ship.

Write coveVerdicts(writs, queries).

`writs` is a list of strings, in the order they were issued. Each string is exactly three words separated by single spaces: a *word*, a *ship* and a *cove*. - The ship is either a ship's name or *, meaning any ship. The cove is either a cove's name or *, meaning any cove. Names are compared exactly and are case-sensitive. - The word is one of open, shut, open!, shut! or void. A trailing ! marks the writ as warded.

Void writs. A void writ removes every writ that appears *earlier* in the list whose ship field and cove field are textually identical to its own. It removes warded and unwarded writs alike. Matching is by the exact words, not by what they cover: void * * removes only earlier writs whose ship and cove are both literally *. A void never affects writs issued after it, and a void writ never rules on any query itself.

`queries` is a list of [ship, cove] pairs. Both are names; neither is ever *.

For each query, consider every open/shut writ (warded or not) that has not been removed by a void and that fits the query: its ship is * or equals the query's ship, and its cove is * or equals the query's cove. - If no writ fits, the verdict is "shut". - Otherwise exactly one fitting writ wins, decided by these rules in order: 1. A warded writ beats any unwarded writ. 2. Among writs tied on rule 1, the one that names more beats the other. From highest to lowest: names both ship and cove; names the ship only (cove is *); names the cove only (ship is *); names neither. 3. Among writs tied on rules 1 and 2, the one issued later in the list wins.

The verdict is the winning writ's word without any !.

Return a list of strings, one per query in the same order, each "open" or "shut". An empty queries list returns an empty list.

  • rule engines with overrides
  • Master

examples

  1. case 1writs "open * *", "shut Gannet *", "open * Blackwater"; query: the Gannet at Blackwater"shut" - all three fit, none is warded, and naming the ship outranks naming the cove, even though the cove writ came later
  2. case 2writs "shut! * Blackwater", "open Kestrel Blackwater"; query: the Kestrel at Blackwater"shut" - the warded writ wins although the other names both ship and cove
  3. case 3writs "open Kestrel *", "shut * *", "void * *"; queries: the Kestrel at Blackwater, the Gannet at Blackwater["open", "shut"] - the void strikes only the literal "* *" writ; the Gannet then has no fitting writ and is shut by default
reward
540 XP
signature
coveVerdicts
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…
  • full name outranks cove-only and default applies
  • ship-named outranks cove-named regardless of order
  • later writ wins among equal rank
  • warded beats more specific
  • among warded writs rank then order decides
  • void strikes a warded writ
  • void matches words not coverage
  • void spares later writs and harmless voids
  • void strikes every earlier identical writ
  • no writs at all
  • no queries
  • full tangle of writs
The Cove-Writs of Corrigal Sound · bitwick