Let's consider the following sequence:
$$9,8,7,6,5,4,3,2,1,0,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71...$$ This is the sequence of \$9\$'s complement of a number: that is, \$ a(x) = 10^d - 1 - x \$ where \$ d \$ is the number of digits in \$ x \$. (A061601 in the OEIS).Your task is to add the first \$n\$ elements.
Input
A number \$n∈[0,10000]\$.
Output
The sum of the first \$n\$ elements of the sequence.
Test cases
0 -> 0
1 -> 9
10 -> 45
100 -> 4050
1000 -> 408600
10000 -> 40904100
Standard code-golf rules apply. The shortest code in bytes wins.
0 -> 0
works if you take 0 as a 0-digit number, and the formula is10^d - 1 - x
as stated. But1 -> 9
only works if the formula is10^d - x
. I think the 0 case should just be removed, and the formula changed to be without the- 1
. \$\endgroup\$0
and then taking sum of first elements. So taking sum of first0
elements results in0
and taking first element (of index0
) results in9
. \$\endgroup\$