Cody

# Problem 45275. Solve Sudoku puzzle step by

Solution 2101116

Submitted on 21 Jan 2020 by Binbin Qi
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
s = [5 0 0 0 0 6 0 0 0 9 0 0 0 0 0 2 7 0 0 0 8 0 0 7 4 0 0 0 2 0 3 9 0 0 0 0 1 0 0 0 0 0 0 0 8 0 0 0 0 4 2 0 6 0 0 0 7 4 0 0 8 0 0 0 5 1 0 0 0 0 0 4 0 0 0 6 0 0 0 0 9]; n = nnz(s==0); for t = 1 : n tt = mat2cell(s,[3,3,3],[3,3,3]); [i,j,d] = your_fcn_name(s); s(i,j) = d; rc = histcounts(setdiff(s(i,:),0)); cc = histcounts(setdiff(s(:,j),0)); gr = ceil(i/3); gc = ceil(j/3); gcc = histcounts(setdiff(tt{gr,gc},0)); assert(max(rc)==1&max(cc)==1&max(gcc)==1); end M = cellfun(@(x)x(:)',mat2cell(s,[3,3,3],[3,3,3]),'UniformOutput',false); p = [s;s';cell2mat(M(:))]; assert(isequal(unique(sort(p,2), 'rows'),1:9));

2   Pass
s = [9 0 0 8 0 7 0 0 0 0 0 0 0 0 0 7 3 5 3 0 7 0 1 0 0 0 0 0 7 0 3 0 8 0 6 0 5 0 0 0 0 0 0 0 7 0 4 0 7 0 2 0 1 0 0 0 0 0 7 0 8 0 3 7 6 4 0 0 0 0 0 0 0 0 0 1 0 5 0 0 9]; n = nnz(s==0); for t = 1 : n tt = mat2cell(s,[3,3,3],[3,3,3]); [i,j,d] = your_fcn_name(s); s(i,j) = d; rc = histcounts(setdiff(s(i,:),0)); cc = histcounts(setdiff(s(:,j),0)); gr = ceil(i/3); gc = ceil(j/3); gcc = histcounts(setdiff(tt{gr,gc},0)); assert(max(rc)==1&max(cc)==1&max(gcc)==1); end M = cellfun(@(x)x(:)',mat2cell(s,[3,3,3],[3,3,3]),'UniformOutput',false); p = [s;s';cell2mat(M(:))]; assert(isequal(unique(sort(p,2), 'rows'),1:9));

### Community Treasure Hunt

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

Start Hunting!