Problem 44705. Expand 10^n to Powers of 4
Given an integer n, return the coefficients
c = [c_n,c_n1,...,c_0]
Such that
10^n = c_n*4^(n) + c_n1*4^(n1) +...+ c_0*4^(0)
With the constraint that
c_n = c_0
For example,
n = 1 10^n = 10 = 2*4^(1) + 2*4^(0), so c = [2 2]
Solution Stats
Problem Comments

2 Comments
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 base4, 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.
Solution Comments
Show commentsProblem Recent Solvers41
Suggested Problems

Project Euler: Problem 3, Largest prime factor
1412 Solvers

334 Solvers

Create logical matrix with a specific row and column sums
301 Solvers

Is this triangle rightangled?
5718 Solvers

172 Solvers
More from this Author18
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!