Let's consider the sequence \$S\$ consisting of one \$1\$ and one \$0\$, followed by two \$1\$'s and two \$0\$'s, and so on:
(This is A118175: Binary representation of n-th iteration of the Rule 220 elementary cellular automaton starting with a single black cell.)
Given \$n>0\$, your task is to output \$a(n)\$, defined as the number of \$1\$'s among the \$T(n)\$ first terms of \$S\$, where \$T(n)\$ is the \$n\$-th triangular number.
The first few terms are:
One way to think of it is to count the number of \$1\$'s up to the \$n\$-th row of a triangle filled with the values of \$S\$:
1 (1) 01 (2) 100 (3) 1110 (6) 00111 (9) 100001 (11) 1111000 (15) 00111111 (21) 000000111 (24) 1111000000 (28) 01111111100 (36) ...
You may either:
- take \$n\$ as input and return the \$n\$-th term, 1-indexed
- take \$n\$ as input and return the \$n\$-th term, 0-indexed
- take \$n\$ as input and return the \$n\$ first terms
- take no input and print the sequence forever
This is a code-golf challenge.