Consider a matrix x
x = [ 1 2 0
0 5 0
3 0 8 ]If we sum x along the rows we get
row_sums = [3 5 11]
Summing along the columns gives
col_sums = [4 7 8]
Metaphorically, we might call these sums "x-rays". Your job is to take these x-rays and reconstruct the matrix x being x-rayed, in the fashion of a CAT scan. Can you put all the bones in the right place?
All matrix elements must be non-negative integers. There is no guarantee of a unique answer. I will only check that the row and column sums match the supplied matrix, and that your elements are non-negative integers.
Bonus question: Under what circumstances does the answer become unique? Discuss.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers145
Suggested Problems
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15780 Solvers
-
Project Euler: Problem 16, Sums of Digits of Powers of Two
178 Solvers
-
1346 Solvers
-
538 Solvers
-
301 Solvers
More from this Author54
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
regarding the discussion question, my guess is that the only cases where the answer becomes unique are those 'trivial' single-vector or equivalent cases. More precisely those cases where min(nnz(row_sums),nnz(col_sums))<=1. The reasons is that if one solution exist where x(a,b)>0 and x(c,d)>0 (and a~=c and b~=d; i.e. they are not in the same row or column), then you could simply subtract one from x(a,b) and x(c,d), and add one to x(c,b) and x(a,d), and the result will also be a valid solution... thoughts?
Nice problem
good problem.
See also this: https://it.mathworks.com/matlabcentral/cody/problems/47618
There is a nice video explaining how to solve these problems.