‹ back to the board

Friday, September 4

Novicesyntax & basics

The Ferryman's Silver Toll

The ferryman at bitwick's south landing keeps his ledger in copper but his strongbox holds only silver. Every crossing is priced in copper, and the fare must be settled in whole silver coins — he gives no change, and he will not push off a single copper short.

You are given two integers:

  • toll — the price of the crossing in copper, zero or greater.
  • rate — how many copper one silver coin is worth, always one or greater.

Write silverToll(toll, rate), which returns an integer: the smallest number of whole silver coins whose total copper value is at least toll.

  • numeric conversion and rounding
  • Novice

examples

  1. case 1toll of 25, rate of 123 — two silver are worth 24 copper, one short, so a third is needed
  2. case 2toll of 24, rate of 122 — the fare divides evenly, so no extra coin
  3. case 3toll of 0, rate of 70 — nothing owed, nothing paid
reward
130 XP
signature
silverToll
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…
  • one copper over two silver
  • exact multiple takes no extra coin
  • no toll at all
  • a single copper still costs a coin
  • copper and silver worth the same
  • a long crossing
  • one short of an even trade
The Ferryman's Silver Toll · bitwick