The Miller's Whole-Stone Tally
# The Miller's Whole-Stone Tally
The mill at the edge of bitwick weighs every sack on a scale that reads fractions, but the tally board nailed above the hopper has room only for whole numbers. The miller wants the board filled in before the carts arrive.
weights is a list of non-negative numbers, one per sack, each a weight in stones.
Write tallyStones(weights), which returns a new list of the same length, in the same order. Each entry is the matching weight rounded to the nearest whole stone, and a weight lying exactly halfway between two whole stones rounds up to the larger one. Every returned value is a whole number. An empty list of weights returns an empty list.
examples
- case 1
weights of 2.5, 2.4, 2.6[3, 2, 3] — the halfway sack goes up to 3 - case 2
weights of 0.5, 3.5[1, 4] — both are exact halves, both round up - case 3
an empty list of weightsan empty list
- reward
- 110 XP
- signature
tallyStones
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- exact halves all round up
- empty board
- zero and small fractions
- mixed cart of sacks
- single heavy sack