Cody

# Problem 1286. MatCAT - Reconstruct X from Its X-rays

Solution 2921077

Submitted on 7 Sep 2020 by Jens Kjærgaard Boldsen
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
row_sums = [3 5 11]; col_sums = [4 7 8]; x = matcat(row_sums,col_sums); assert(all(x(:)>=0)) assert(isequal(floor(x),x)) assert(isequal(sum(x,2)',row_sums)) assert(isequal(sum(x,1),col_sums))

x = 0 1 1 1 1 2 2 4 4 xfrac = 1 1 1 1 1 1 1 1 1 x = 1 1 1 1 1 2 2 4 4 xfrac = 0 0 0 0 1 1 0 1 1 x = 1 1 1 1 2 2 2 4 4 xfrac = 0 0 0 0 0 0 0 0 1 x = 1 1 1 1 2 2 2 4 5

2   Pass
row_sums = [2 2 2 2 2 6]; col_sums = [2 3 3 3 3 2]; x = matcat(row_sums,col_sums); assert(all(x(:)>=0)) assert(isequal(floor(x),x)) assert(isequal(sum(x,2)',row_sums)) assert(isequal(sum(x,1),col_sums))

x = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 xfrac = 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 x = 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 xfrac = 1 2 2 2 2 2 2 4 4 4 4 4 2 4 4 4 4 4 2 4 4 4 4 4 2 4 4 4 4 4 2 4 4 4 4 4 x = 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 xfrac = 1 1 2 2 2 2 1 1 2 2 2 2 2 2 4 4 4 4 2 2 4 4 4 4 2 2 4 4 4 4 2 2 4 4 4 4 x = 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0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 0 1 1 1 x = 2 0 0 0 0 0 0 2 0 0 0 0 0 0 2 0 0 0 0 0 0 2 0 0 0 0 0 0 1 0 0 1 1 1 1 1 xfrac = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 x = 2 0 0 0 0 0 0 2 0 0 0 0 0 0 2 0 0 0 0 0 0 2 0 0 0 0 0 0 2 0 0 1 1 1 1 1 xfrac = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 x = 2 0 0 0 0 0 0 2 0 0 0 0 0 0 2 0 0 0 0 0 0 2 0 0 0 0 0 0 2 0 0 1 1 1 1 2

3   Pass
row_sums = [65 65 65 65 65]; col_sums = [65 65 65 65 65]; x = matcat(row_sums,col_sums); assert(all(x(:)>=0)) assert(isequal(floor(x),x)) assert(isequal(sum(x,2)',row_sums)) assert(isequal(sum(x,1),col_sums))

x = 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13

4   Pass
row_sums = [22 34 33]; col_sums = [15 23 18 21 12]; x = matcat(row_sums,col_sums); assert(all(x(:)>=0)) assert(isequal(floor(x),x)) assert(isequal(sum(x,2)',row_sums)) assert(isequal(sum(x,1),col_sums))

x = 3 5 4 5 2 5 8 6 8 4 5 8 6 7 4 xfrac = 6 6 6 3 6 6 6 6 3 6 6 6 6 3 6 x = 4 5 4 5 2 5 8 6 8 4 5 8 6 7 4 xfrac = 2 4 4 2 4 3 6 6 3 6 3 6 6 3 6 x = 4 5 4 5 2 5 9 6 8 4 5 8 6 7 4 xfrac = 2 2 4 2 4 2 2 4 2 4 3 3 6 3 6 x = 4 5 4 5 2 5 9 6 8 4 5 8 7 7 4 xfrac = 2 2 2 2 4 2 2 2 2 4 2 2 2 2 4 x = 4 5 4 5 3 5 9 6 8 4 5 8 7 7 4 xfrac = 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 x = 4 5 4 5 3 6 9 6 8 4 5 8 7 7 4 xfrac = 0 1 1 1 1 0 1 1 1 1 0 2 2 2 2 x = 4 5 4 5 3 6 9 6 8 4 5 9 7 7 4 xfrac = 0 0 1 1 1 0 0 1 1 1 0 0 1 1 1 x = 4 5 5 5 3 6 9 6 8 4 5 9 7 7 4 xfrac = 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 x = 4 5 5 5 3 6 9 6 9 4 5 9 7 7 4 xfrac = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 x = 4 5 5 5 3 6 9 6 9 4 5 9 7 7 5

5   Pass
row_sums = 55; col_sums = [1 2 3 4 5 6 7 8 9 10]; x = matcat(row_sums,col_sums); assert(all(x(:)>=0)) assert(isequal(floor(x),x)) assert(isequal(sum(x,2)',row_sums)) assert(isequal(sum(x,1),col_sums))

x = 1 2 3 4 5 6 7 8 9 10

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!