‹ back to the board

Saturday, October 31

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 0 is a landed blow with that base force.
  • A value of 0 is 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.

  • running state across iterations
  • Apprentice

examples

  1. case 1strikes of [3, 5, 0, 2, 2, 2, 2, 2]41 (3x1 + 5x2, then the miss resets, then 2x1 + 2x2 + 2x3 + 2x4 + 2x4)
  2. case 2strikes of [1, 1, 1, 1, 1, 1]18 (the streak stops climbing at 4: 1 + 2 + 3 + 4 + 4 + 4)
  3. case 3strikes of []0
reward
210 XP
signature
glaiveDamage
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…
  • empty record
  • all misses
  • single blow
  • streak caps at four
  • mixed bout
  • alternating hits and misses
  • double miss then hit
  • rising forces past cap
The Thunder-Glaive of Orrenhall Arena · bitwick