The sequence contains the decimal representation of the binary numbers of the form: 10101...
, where the n-th term has n bits.
The sequence is probably easiest to explain by just showing the relationships between the binary and decimal representations of the numbers:
0 -> 0
1 -> 1
10 -> 2
101 -> 5
1010 -> 10
10101 -> 21
101010 -> 42
Challenge:
Take an input integer n
, and return the first n numbers in the sequence. You may choose to have the sequence 0-indexed or 1-indexed.
Test cases:
n = 1 <- 1-indexed
0
n = 18
0, 1, 2, 5, 10, 21, 42, 85, 170, 341, 682, 1365, 2730, 5461, 10922, 21845, 43690, 87381
Explanations are encouraged, as always.
This is OEIS A000975.
[85,[42,[21,[10,[5,[2,[1,0]]]]]]]
? \$\endgroup\$