Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

how to use maple to solve this sudoku question? thank you! How to use maple to s

ID: 3401606 • Letter: H

Question

how to use maple to solve this sudoku question? thank you!

How to use maple to solve this sudoku question? Thank you!

Explanation / Answer

> L := Matrix(4,4,[ [0,4,0,0],[2,0,0,3],[4,0,0,1],[0,0,3,0] ]); > isFull := proc(L) local x, y; for x from 1 to 4 do for y from 1 to 4 do if L[x,y]=0 then return false; end if; end do; end do; return true; end proc; >findPossibleEntries := proc(L, i, j) local x, y, possible:=[0,0,0,0]; local r:=1, c:=1; #Checking possible entries in ith row for y from 1 to 4 do if not L[i,y] = 0 then possible[L[i,y]] := 1; end if; end do; #Checking possible entries in jth col for x from 1 to 4 do if not L[x,j] = 0 then possible[L[x,j]] := 1; end if; end do; #Checking possible entries block by block if i >= 1 and i = 3 and i = 1 and j = 3 and j SolveSmallSudoku := proc(L) local x, y, i:=0, j:=0, possibleVal:=[0,0,0,0]; if isFull(L) then print("Solved!"); print(L); return; else print("Solving now..."); for x from 1 to 4 do for y from 1 to 4 do if L[x,y] = 0 then i:=x; j:=y; break; end if end do; #Breaks the outer loop as well if L[x,y] = 0 then break; end if end do; #Finds all the possibilities for i,j possibleVal := findPossibleEntries(L,i,j); #Traverses the list, possibleVal to find the correct entries and finishes the sudoku recursively for x from 1 to 4 do if not possibleVal[x] = 0 then L[i,j]:= possibleVal[x]; SolveSmallSudoku(L); end if; end do; #Backtracking L[i,j]:= 0; end if; end proc;