Combo Level Score
Context
In a training challenge, each level of a combo grants a smaller bonus than the previous one. Level 0 is worth 1 point, level 1 is worth 1/2 point, level 2 is worth 1/4 point, and so on. The game wants the total bonus from level 0 through a supplied highest level.
Problem
Implement a function that returns the total combo bonus for every level from 0 through highest_level. The bonus for level n is (1/2)^n. Define the recursive calculation so that a state below level 0 returns the neutral total 0. Each nonterminal state must include its own bonus and combine it with the result for the immediately smaller level. A highest_level of -1 therefore represents no levels and has total 0.
Examples
highest_level = -10highest_level = 01highest_level = 31.875Constraints
-1 <= highest_level <= 60- Types:
highest_levelis int; result is float
Function signature
def combo_level_score(highest_level: int) -> float
highest_levelint- The highest combo level whose bonus should be included.
- returns float
- The sum of the bonuses for levels 0 through highest_level, or 0.0 when the level is below 0.
Adapted from MBPP problem task_738 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- The level contribution uses a fixed ratio of one half.
- The terminating state is below the lowest valid level.