The Toll Gate of Wyrmback Bridge
A notice, pinned by the door of the Wick & Whistle inn.
The toll-keeper at Wyrmback Bridge has lost her tally-clerk to the harvest, and the morning caravan is already queued on the far bank. She needs someone to total up a day's takings.
You are given carts, a list of carts in the order they reach the gate. Each cart is a 3-element list [kind, weight, wheels], where kind is a string, weight is a positive integer (the load in stones), and wheels is a positive integer.
The posted toll for a single cart, in coins:
- If
kindis"grain": nothing at all whenweightis 100 or less; otherwise1 + (weight - 100) // 50coins, using floor division. - If
kindis"stone": 5 coins, plus 10 more ifweightis greater than 300, or else plus 4 more ifweightis greater than 150. - If
kindis"cloth": 4 coins ifweightis greater than 200, and 2 coins otherwise. - Any other value of
kindis not on the posted list: that cart is waved through for 0 coins, and no further charge of any sort applies to it.
Then, for every cart that is on the posted list and whose kind is not "grain", add 3 coins if wheels is greater than 4.
Write bridgeToll(carts), which returns the sum of the tolls of all the carts as an integer. An empty list of carts returns 0.
examples
- case 1
carts of [["stone", 151, 4]]9 — 5 base, plus 4 because the weight passes 150; only 4 wheels, so no wheel charge - case 2
carts of [["grain", 250, 6]]4 — 1 + (250 - 100) // 50 = 4, and grain never pays the wheel charge whatever the count - case 3
carts of [["ash", 40, 2], ["cloth", 201, 5]]7 — ash is not on the posted list and pays nothing; the cloth pays 4 plus 3 for its fifth wheel
- reward
- 200 XP
- signature
bridgeToll
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- no carts at the gate
- grain bands and grain's wheel exemption
- stone weight bands
- cloth boundary at two hundred stones
- a fifth wheel on a light stone cart
- unlisted cargo is waved through
- the whole morning caravan