Cody

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

Solution 1547250

Submitted on 3 Jun 2018 by Riccardo Dessì
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))

xx = 4 0 0 -1 5 3 0 0 8 xx = 3 1 0 0 0 7 0 4 4 X = 3 0 0 1 0 4 0 7 4

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))

xx = 2 0 0 0 0 0 1 2 0 0 0 0 2 0 2 -1 0 0 0 0 0 3 0 0 -3 0 0 0 2 4 0 0 0 0 0 2 xx = 0 2 0 0 0 0 1 0 0 2 0 0 0 0 3 0 0 0 0 0 -1 0 0 4 1 0 0 0 2 0 0 0 0 0 0 2 xx = 0 0 0 0 2 0 2 0 0 0 1 0 0 0 2 0 1 0 0 3 0 0 0 0 0 -1 0 6 -2 0 0 0 0 -4 0 6 xx = 0 0 0 0 2 0 5 0 0 -2 0 0 0 3 0 0 0 0 0 0 0 3 0 0 0 0 2 1 0 0 -3 -1 0 0 0 6 xx = 0 0 0 2 2 -2 0 0 3 0 0 0 0 3 0 0 0 0 0 -1 0 0 0 4 4 0 -1 0 0 0 -2 0 0 0 0 4 xx = 0 0 0 0 2 0 0 -1 0 0 0 4 0 0 3 0 0 0 0 3 0 0 0 0 1 0 0 2 0 0 1 0 -1 0 0 2 xx = 0 0 0 2 0 0 0 0 3 0 0 0 0 0 3 0 0 0 0 1 0 0 2 0 1 0 -4 0 0 6 1 1 0 0 0 0 xx = 0 2 -2 0 2 0 0 0 3 0 0 0 0 0 0 0 0 3 0 0 0 0 0 3 1 0 0 2 0 0 1 0 1 0 0 0 xx = 4 0 0 2 -4 0 -4 0 2 0 0 5 0 0 0 0 3 0 0 2 0 0 0 1 0 0 0 0 3 0 2 0 0 0 0 0 xx = 2 0 0 0 0 0 1 0 0 0 0 2 -1 0 2 0 2 0 0 0 0 0 0 3 0 0 0 2 0 1 0 2 0 0 0 0 xx = 2 0 0 0 0 0 0 0 0 0 -3 6 0 2 2 0 -1 0 -3 0 0 0 6 0 1 0 0 2 0 0 2 0 0 0 0 0 xx = 2 0 0 0 0 0 0 0 0 0 0 3 0 2 0 0 1 0 0 0 0 0 0 3 0 0 0 2 1 0 0 0 2 0 0 0 X = 2 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 2 0 0 0 0 2 0 0 0 1 0 1 0 0 3 0 3 0 0

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))

xx = 65 0 0 0 0 0 65 0 0 0 0 0 65 0 0 0 0 0 65 0 0 0 0 0 65 X = 65 0 0 0 0 0 65 0 0 0 0 0 65 0 0 0 0 0 65 0 0 0 0 0 65

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))

xx = 15 0 0 -14 22 15 0 0 18 21 0 0 0 12 0 xx = 0 15 0 0 0 23 0 8 10 22 -1 0 0 12 0 xx = 0 0 15 0 0 23 18 0 0 21 0 0 -17 34 -5 xx = 0 15 0 0 7 16 1 0 17 21 0 0 0 12 0 X = 0 0 1 21 0 15 7 0 0 12 0 16 17 0 0

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))

xx = 1 2 3 4 5 6 7 8 9 10 X = 1 2 3 4 5 6 7 8 9 10