Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Assignment 4 - Sudoku Solver Sudoku is a fun little logic puzzle where the objective is to fill a 9x9 grid with digits so

image text in transcribedimage text in transcribed

Programming Assignment 4 - Sudoku Solver Sudoku is a fun little logic puzzle where the objective is to fill a 9x9 grid with digits so that each column, each row, and each of the nine 3x3 sub-grids contain all digits from 1 to 9. Solving one of these involves a lot of testing and back-tracking when numbers don't work out. It's not something a simple program loop can do, but it's perfect for our new tool: recursion. For more info on Sudoku: https://en.wikipedia.org/wiki/Sudoku Program requirements: Create a new class called Sudoku.java Inside your main program, create an array of arrays of size 9x9 (see code below). For empty spots, use the number 0. Your program must use a recursive backtracking algorithm to solve for each square. This algorithm will attempt to fill each spot in the array with a number (1-9) and check if the number has been used in the row, column, or the 3x3 sub-grid. To accomplish this with recursion, here is the general flow in pseudo-code: solveSudoku () Loop through each row Loop through each column if this row/column combination has no number assigned Loop through numbers 1-9 Check to see if the number is valid here if yes, do solveSudoku () if no, this row/column combo is unassigned end loop return false end loop for column end loop for row return true end For the is valid check, you should make three functions: isinRow(), isinColumn(), and isInGrid(). Then call each one for your candidate number. Create and call a method that prints out the board before and after the solution is made Optional: note that this program only attempts to solve the puzzle but doesn't confirm if it is complete. How could you use recursion to both solve for and verify your solution? Here's a bit of code that will fill your array up and get you started going forward: public class Sudoku { public static int SIZE = 9; public static int[][] PUZZLE = { {9,0,0,1,0,0,0,0,5}, {0,0,5,6,9,0,2,0,1}, {8,0,0,0,4,0,0,0,0}, {0,0,0,0,8,0,0,0,0}, {0,0,0,7,0,0,0,0,0}, {0,0,0,0,2,6, 0,6,9}, {2,0,0,3,0,0,0,0,6}, {0,0,0,2,0,0,9,9,0}, {0,0,1,9,6,4,5,7,0}, public static boolean solveSudoku() { // our recursive algorithm return true; } public static void main(String[] args) { int[][] board = new int[SIZE][SIZE]; 11 fill in the temporary board with the puzzle for (int i = 0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+and non-compete agreements in three to five different countries.

Answered: 1 week ago