Challenge:
Given the input number n
. It should give me nested sublists of n
layers with the power of two numbers for each level. Each power of two value will be in separate sublists.
Notes:
n
will always be greater than 0I am using the example output with Python Lists. You can use any type of sequence in your own language.
Your output must be one-indexed, add one to
n
if your output is zero-indexed.Your output sequence must be nested.
Test cases:
n = 1: [1]
n = 2: [1, [2]]
n = 3: [1, [2, [4]]]
n = 4: [1, [2, [4, [8]]]]
n = 5: [1, [2, [4, [8, [16]]]]]
n = 6: [1, [2, [4, [8, [16, [32]]]]]]
n = 7: [1, [2, [4, [8, [16, [32, [64]]]]]]]
This is code-golf, so the shortest code in bytes wins!
The power of twos are these values 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048...
, each values is double of the previous value.
[1, [2, [4, [8]]]]
\$\endgroup\$3
=>[1, [2, [4, [8]]]]
) \$\endgroup\$