‹ back to the board

Tuesday, September 8

Novicesyntax & basics

The Millpond Ferryman's Toll

The ferry at Millpond crosses with grain sacks stacked on its deck, and the ferryman is paid the same coins for every crossing whether the deck is full or holds a single sack.

Write ferryToll(sacks, load, fee):

  • sacks is a non-negative integer: how many sacks must reach the far bank.
  • load is an integer of 1 or more: the greatest number of sacks the deck holds in one crossing.
  • fee is a non-negative integer: the coins charged for one crossing.

Return an integer: the total coins owed for carrying all the sacks across, counting one fee per crossing made. Only crossings that carry sacks are counted; the empty trips back are free.

  • simple arithmetic
  • Novice

examples

  1. case 1sacks of 7, load of 3, fee of 212 sacks... no: 3 crossings (3, 3, 1) at 2 coins each = 6
  2. case 2sacks of 6, load of 3, fee of 22 crossings (3, 3) at 2 coins each = 4
  3. case 3sacks of 0, load of 4, fee of 50 - the ferry never leaves the bank
reward
130 XP
signature
ferryToll
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…
  • leftover sacks need an extra crossing
  • exact multiple of the deck load
  • nothing to carry
  • one sack on a wide deck
  • a hundred sacks, seven at a time
  • a free ferryman
  • one sack at a time
The Millpond Ferryman's Toll · bitwick