A nice puzzle by way of @benjaminleis:

In case you can’t read that, we need to find the sum of the digits in $N = 9 + 99 + 999 + 999\dots999$, where the last number consists of 321 consecutive nines.

As usual, I’ll let you pause to think about it here and post spoilers below the line.

It feels geometric!

It feels like a geometric sequence - and it sort of is, although it took me a while to spot it. It also looks like it’s related to the decimal expansion of fractions, although that turned out to be a dead-end.

The trick (for me, at least), is to write each term as $10^k - 1$.

Then we’re looking at $N = \sum_{k=1}^{321} \left( 10^k - 1\right)$.

We can split that into two sums: a geometric sequence and $321\times1$. We could bring out the formula for that, but why would we? It’s going to be a string of 321 ones with a zero at the end.

From that, we need to subtract 321 - and we only really care about the last four digits here: $1110 - 321 = 0789$.

So, we’ve still got 318 ones in our string (the digits of which sum to 318), followed by 0789 (the digits of which sum to 24), making a total of 342.

Quick check

The number $N$ is a multiple of 9, so its digits sum to a multiple of 9. It’s worth checking that our answer makes sense: is 342 a multiple of 9? Well, its digits sum to 9, so it looks plausible! (It’s $38\times 9$, the Ninja murmurs in their sleep).

It doesn’t mean we definitely have the right answer - but it increases our confidence slightly; had we got something that wasn’t a multiple of 9, we’d know we had it wrong.

I enjoyed that puzzle. Did you tackle it a different way?