Is there a way to calculate each element of these sequences individually without having to calculate the previous element or sequence?
Sequence 1: [2]
Sequence 2: [4, 2, 6]
Sequence 3: [8, 4, 12, 2, 10, 6, 14]
Sequence 4: [16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14, 30]
Sequence 5: [32, 16, 48, 8, 40, 24, 56, 4, 36, 20, 52, 12, 44, 28, 60, 2, 34, 18, 50, 10, 42, 26, 58, 6, 38, 22, 54, 14, 46, 30, 62]
etc.
I know how to generate them recursively, as the first half of the next sequence is just prev_sequence[i] * 2
and the second half is prev_sequence[i] * 2 + 2
(when you prefix 0 to the sequence).
There seems to be an internal pattern. Looking at e.g. the sequence 3, it starts with 8, the next two numbers are 8-4 = 4
and 8+4 = 12
. The next four numbers are the last two interleaved, where the first half is number-2
and the second half is number+2
. The sequence 4 starts the internal pattern with -8
and +8
then continues to half if for the next "levels".
I feel that this is more of a math question than a programming one, hence the question is here. I'm sorry for not phrasing my question in a more mathematical way.
Thanks to everyone in advance.