The Tremor-Rods of Cindral Caldera
Commission of the Cindral Caldera Wardens
Around the rim of Cindral Caldera stand iron tremor-rods, each driven deep into the black rock. Every dusk a warden reads how far the caldera floor beneath a rod has moved since the last reading. The distance is measured in spans: positive when the floor has risen, negative when it has sunk. The brass dials on the rods show fractions of a span, but the Wardens' basalt record-stones can only be carved with whole numbers. The custom of the Wardens is to chip away the fractional part of each reading and carve what remains.
Write carveReadings(readings).
readingsis a list of numbers, one per rod. Each may be a whole number or have a fractional part, and each may be positive, negative, or zero. The list may be empty.- Return a new list of integers, the same length and in the same order as
readings. Each element is the matching reading with its fractional part removed, which is truncation toward zero. For example,3.7becomes3and-3.7becomes-3. A reading that is already whole stays as it is.
No reading will lie strictly between -1 and 0.
examples
- case 1
readings of [3.7, -3.7, 5][3, -3, 5] - case 2
readings of [12.5, -12.5, 0.4][12, -12, 0] - case 3
readings of [] (no rods read tonight)[]
- reward
- 130 XP
- signature
carveReadings
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- positive fractions
- negative readings move toward zero
- empty list
- already whole readings
- halves and near-whole values
- small positive and whole float
- single reading