フィルターのクリア

Matlab Sudoku Row and Column Check

4 ビュー (過去 30 日間)
Katrina
Katrina 2015 年 10 月 29 日
回答済み: Tushar Sinha 2015 年 11 月 2 日
I need to solve a Sudoku puzzle with Matlab and I'm not sure how to check the rows and columns in order to solve the puzzle. I am creating a "Can't be" 9x9x9 matrix to fill in what can't go in each square. So in the 3D section a 0 placeholder indicates the number can be used. My thought is to sum each row and column for 1-9 (so 45) and check for unique values, but I don't know how to do that. I've tried looking at code online, but I don't understand their process. Any help or ideas to checking the rows and columns is greatly appreciated! Thank you!
Here is my code so far for inserting the known puzzle squares into the "Can't Be" matrix:
function [ cantbe ] = Setcantbe( Sudoku )
cantbe=zeros(9,9,9)
for i=1:9
for j=1:9
if Sudoku(i,j)~=0
a=Sudoku(i,j)
for k=1:9
if k~=a
cantbe(i,j,k)=k
end
if Sudoku(i,j)==0 && k~=j
%And this is where I get stuck in filling the rows and columns that are blank
end
end
end
end
end

回答 (1 件)

Tushar Sinha
Tushar Sinha 2015 年 11 月 2 日
Hi Katrina
Please refer to the MathWorks newsletter article link below which shows how to solve a Sudoku puzzle using recursive backtracking in MATLAB:
I hope this helps resolve the issue.
Thanks, Tushar

カテゴリ

Help Center および File ExchangeSudoku についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by