Skip to the content

Hit combo

Problem

In Neon Fist, every hit is worth as much as your current combo: the first one you land is worth 1, the second in a row is worth 2, the third 3, and so on. Miss one and the combo drops back to zero, but the points you already earned stay with you.

Write a function that takes the fight as a text of x (a hit that lands) and . (a missed hit), and returns the total points as a whole number. With "xx.xxx": 1 + 2 for the first two, the miss adds nothing and resets the combo, and then 1 + 2 + 3. You return 9.

The text only has lowercase x and ., and it can be empty: no hits means 0 points.

Examples

  • Three in a row

    "xxx" → 6

  • Hit and miss, taking turns

    "x.x.x" → 3

  • A combo that breaks

    "xxxx.xx" → 13

  • An empty fight

    "" → 0

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def combo_points(fight):
    pass

JavaScript

function comboPoints(fight) {
}
Solve this challenge

It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.

More O(n) challenges

See all challenges →