Is there an algorithm to generate these specific sequences of numbers?

61 Views Asked by At
f(1) = [1] 
f(2) = [2,1,1]
f(3) = [3,2,1,1,2,1,1]
f(4) = [4,3,2,1,1,2,1,1,3,2,1,1,2,1,1]
...
f(n) = ...

The lengths of the lists f(n) are $2^n - 1$ (Mersenne numbers).

How would one write a recursive algorithm to generate lists f(n)?

1

There are 1 best solutions below

0
On BEST ANSWER

$$f(n) = [n] + f(n-1) + f(n-1); \quad f(1) = [1]$$

where "+" in this context represents concatenation.