Tuesday, 15 June 2010

matlab - Sudoku Solver, check each 3x3 box -



matlab - Sudoku Solver, check each 3x3 box -

to sum problem in nutshell, checking each 3x3 box if there 1 missing value, if there is, computes number is, , fills number in. however, upper left 3x3 box, , stops there. here snippet of code relates issue. if you'd see rest of code inquire , i'll post rest.

edit: user inputs board. test purposes tried inputting completed sudoku puzzle, , take out top right value in each box. filled in first 3x3, still output board @ end, had 8 other blanks fill in (from other 8 3x3 boxes)

% check each 3x3 box 1 through nine, fill in = 0:2 j = 0:2 if sum(sum(board([1:3]+i*3,[1:3]+j*3)~=0))==8 [row,col] = find(board([1:3]+i*3,[1:3]+j*3)==0); reply = 45 - sum(sum(board([1:3]+i*3,[1:3]+j*3))); board(row,col) = answer; end end end disp(board);

you close. problem each block getting row , column index of 3x3 block. so, each block next true: row <= 3 , col <= 3.

you can solve adding these 2 lines after line utilize find:

row = row + (3*i); col = col + (3*j);

this way convert block-relative index board-relative index.

matlab

No comments:

Post a Comment