‹ back to the board

Friday, October 9

Novicesyntax & basics

The Bog-Bounties of Gorsemere

The Reed Wardens of Gorsemere Marsh pay coin for every beast hunted out of their bogs. Their bounty list maps each beast's name to the coins paid for one trophy of it. A hunter returns with a sack of trophies, one name per trophy, and the Wardens pay out the total.

Write tallyBounty(bounties, trophies), which returns the total coins owed.

  • bounties is a dictionary (object) mapping a beast's name (a string) to a non-negative integer number of coins.
  • trophies is a list of strings, one per trophy brought in. The same name may appear more than once, and each occurrence is paid separately.
  • A trophy whose name is not a key in bounties is worth 0 coins. Names must match a key exactly, including capital letters.
  • Return the total as an integer. If trophies is empty, return 0.
  • dictionary and object access
  • Novice

examples

  1. case 1bounties of { "mire toad": 3, "bog lurker": 40, "wisp": 12 }, trophies of ["mire toad", "wisp", "mire toad"]18 (3 + 12 + 3)
  2. case 2bounties of { "mire toad": 3, "bog lurker": 40, "wisp": 12 }, trophies of ["bog lurker", "swamp cat"]40 (the swamp cat is not on the list, so it pays nothing)
  3. case 3bounties of { "wisp": 12 }, trophies of ["Wisp"]0 ("Wisp" does not exactly match "wisp")
reward
130 XP
signature
tallyBounty
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…
  • repeated trophies are each paid
  • unlisted beast pays nothing
  • empty sack
  • empty bounty list
  • names are case sensitive
  • zero-coin bounty
  • single trophy
The Bog-Bounties of Gorsemere · bitwick