Novicesyntax & basics
The Bridge-Troll's Exact Change
The troll under Marrow Bridge keeps a scale, not a conversation. It weighs a toll in three coins: a crown is worth 60 pennies, a shilling is worth 12 pennies, and a penny is worth 1. The toll-keeper's book records each toll as a plain count of pennies, and the stack handed over must use the heaviest coins first.
Write tollChange(pennies).
penniesis a non-negative integer: the toll owed, counted in pennies.- Return an array (Python: list) of exactly three integers
[crowns, shillings, pennies].
Take as many whole crowns as fit in the toll, then as many whole shillings as fit in what remains, and the rest is left as pennies. All three counts are whole numbers.
examples
- case 1
pennies of 143[2, 1, 11] - two crowns (120), one shilling (12), eleven pennies - case 2
pennies of 59[0, 4, 11] - not enough for a crown, so four shillings and eleven pennies - case 3
pennies of 0[0, 0, 0] - still three counts, all zero
- reward
- 120 XP
- signature
tollChange
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
loading the editor…
- mixed toll of 143
- no toll at all
- one penny short of a crown
- exactly one crown
- pennies only
- a heavy toll