‹ back to the board

Sunday, September 27

Apprenticelogic & control flow

The Miller's Rising Pile

The mill by the north water-wheel keeps a ledger of the grain pile in its yard, measured in whole sacks.

The pile is recorded once each morning. Let d be the sum of the decimal digits of the morning's count. Between that morning and the next, the pile grows:

  • by d sacks if the morning's count is even,
  • by 2 * d sacks if the morning's count is odd.

The yard cannot hold more than a fixed number of sacks, so recording stops as soon as a count would exceed that number.

Write millTally(start, limit). Both arguments are integers with start >= 1 and limit >= 1. Return the list (array) of morning counts, in order, beginning with start and continuing by the rule above, including every count that is less than or equal to limit and no count greater than limit. A count equal to limit is included. If start is already greater than limit, return an empty list.

  • iterative sequence generation
  • Apprentice

examples

  1. case 1start of 12, limit of 60[12, 15, 27, 45] — 12 is even and its digits sum to 3, so the next count is 15; 15 is odd with digit sum 6, so it grows by 12 to 27; 27 grows by 18 to 45; 45 would grow by 18 to 63, which is past 60, so recording stops
  2. case 2start of 24, limit of 30[24, 30] — 24 grows by 6 to exactly 30, which still fits and is recorded; 30 would grow by 3 to 33, which is past the limit
  3. case 3start of 9, limit of 8[] — the pile already exceeds what the yard may hold, so nothing is recorded
reward
200 XP
signature
millTally
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…
  • twelve up to sixty
  • lands exactly on the limit
  • start already over the limit
  • single morning only
  • from one
  • crossing a hundred
  • long haul from ninety-eight
The Miller's Rising Pile · bitwick