Apprenticelogic & control flow
The Thunder-Glaive of Orrenhall Arena
The champions of Orrenhall Arena fight with Thrennic, a thunder-glaive that builds charge with every consecutive blow that lands. The Arena Wardens have posted a bounty for anyone who can reckon the true damage of a bout from the fight-scribe's record.
The record is a list of strikes in the order they were thrown. Each strike is a non-negative integer:
- A value greater than
0is a landed blow with that base force. - A value of
0is a miss.
The glaive keeps a streak, which starts at 0 before the first strike:
- On a landed blow, the streak first increases by 1, but never above
4. The blow then deals its base force multiplied by the current streak. - On a miss, no damage is dealt and the streak resets to
0.
Write glaiveDamage(strikes), where strikes is a list of non-negative integers. It returns the total damage dealt over the whole bout, as an integer. An empty record deals 0 damage.
examples
- case 1
strikes of [3, 5, 0, 2, 2, 2, 2, 2]41 (3x1 + 5x2, then the miss resets, then 2x1 + 2x2 + 2x3 + 2x4 + 2x4) - case 2
strikes of [1, 1, 1, 1, 1, 1]18 (the streak stops climbing at 4: 1 + 2 + 3 + 4 + 4 + 4) - case 3
strikes of []0
- reward
- 210 XP
- signature
glaiveDamage
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
loading the editor…
- empty record
- all misses
- single blow
- streak caps at four
- mixed bout
- alternating hits and misses
- double miss then hit
- rising forces past cap