Good gosh, this problem is SO much more complicated than it sounds.
The description is quite unclear, honestly. No hate but there are some things other people need to know before getting started.
1) The coefficient array that is returned needs to be EXACTLY n+1 in length
2) The first coefficient cannot be zero
3) The 'only' constraint doesn't just apply to c_n & c_0, although the assert does check for that. Your coefficient array must be a pyramid (as I now see in the tags). Had to learn that one the hard way.
i.e. c_n = c_0
BUT ALSO ...
c_n+1 = c_1
c_n+2 = c_2
If you're trying to test your code in your own MATLAB console before posting it and the asserts throw errors (as they did with me) use this instead:
assert(isequal(dot(coeff, 4.^flip(0:n)), 10^n))
assert(isequal(coeff(1), coeff(end)))
assert(coeff(1) > 0)
Overall, interesting problem. Slaved away at it because it got me so frustrated but knowing these things would have saved me quite a bit of time. Good luck to future participants.
Hum, actually Highphi is not quite right. This problem is only confusing because we may think that it is requesting to convert a number to base-4, and that's not the case. Coefficients can be any real numbers with the only constraint being that c_n == c_0. For instance, I've found as a valid solution for n=3 (1000): [2.0000, 16.5000, 151.5000, 2.0000]. And there is probably an infinite number of other solutions, we just have to add enough constraints to find one.
One of the few solutions at Cody that actually deserves its place. Tip of the hat to you, sir.
944 Solvers
360 Solvers
Mirror Image matrix across anti-diagonal
114 Solvers
265 Solvers
Is this triangle right-angled?
2087 Solvers