Question: please code this on matlab! makeSudoko.m Sudoko.m function grid = makeSudoku(seed,n_empty) % Generates a Sudoku puzzle % seed - random generation seed % n_remove -

please code this on matlab!

makeSudoko.m

Sudoko.m

function grid = makeSudoku(seed,n_empty)

% Generates a Sudoku puzzle

% seed - random generation seed

% n_remove - number of empty spots in the puzzle

% Note: Puzzles become increasingly difficult as n_empty is increased

% Also, puzzle made eventually reach a point where multiple solutions

% exist if n_remove is pushed to very high values.

% Seed the random number generator with our seed input,

% then generate a base sequence for making the grid

rng(seed);

base = randperm(9);

% Fill out the grid based on base sequence

for i = 1:9

k = [1 4 7 2 5 8 3 6 9];

grid(i,:) = [base(k(i):9) base(1:k(i)-1)];

end

% Remove values from the grid to make empty spots

grid(randperm(81,n_empty)) = 0;

end

solve sudoko puzzle

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!