Question: In this exercise you will implement your design from Assignment 2 relating to generating (not solving) sudoku problems. Well start with a reminder about what
In this exercise you will implement your design from Assignment 2 relating to generating (not solving) sudoku problems. Well start with a reminder about what sudoku arrays look like, then well talk about generating problems from the sudoku arrays. A Sudoku array is a 9x9 Latin Square, with an additional restriction. Recall from assignment 2 that a Latin Square is an array of NxN integers. Each row and each column contains all the numbers 1-N (inclusive). The additional restriction for a sudoku problem is that the 9x9 grid is subdivided into 3x3 regions which must contain all the numbers 1-9 exactly. For example, the following is a sudoku array, but not a very interesting one. It will be the basis of your implementation, though.
The pattern may be hard to see, but the first column starts with 1 4 7 2 5 8 3 6 9, and the rows simply increase values by one until 9, then start at 1 again. Its a boring Latin Square whose rows have been swapped in a very careful way. A sudoku problem is a puzzle that many people like to solve for relaxation and amusement. A sudoku problem is a sudoku array with some of the numbers blanked out, which are filled in to solve the puzzle. Well generate sudoku problems by starting with a complete and boring sudoku array (the one shown above), randomizing it in a specific way (see below), and then blanking out some of the entries. This creates a sudoku problem that can be solved (though the difficulty of solving depends on the number of blanks). To randomize a sudoku array, you can swap pairs of rows, and pairs of columns, but you can only swap them in limited ways. You can only swap rows 1-3 with another row from 1-3. Likewise, you can only swap rows 4-6 with another row from 4-6. And rows 7-9 can only be swapped with another row from 7-9. The same restrictions apply to the columns. (This is not the best way to create a Sudoku array, but it is the easiest.) Once youve done enough swapping (anywhere from 50-100 swaps), you have to blank out some of the entries. For Sudoku problems that you buy in books, or see on the web, the blanked entries usually form a pattern. Dont worry about that. Randomly choose 25 entries, and replace each of those numbers with a 0 (which is not a valid sudoku number). When youre done, you should have exactly 25 0s in your array. Then you can display it to the console, taking care to print out a blank instead of the 0. Dont draw lines separating rows and columns. Just the entries. Assignment 2 asked you to design this program (most of the hard work, anyway). In this assignment, you will implement your design. The reason youre doing this is to gain experience coding from a design of your own making. It will help you understand how much work to put into your own designs, and what kinds of things are helpful, and what kinds of things you can leave for the implementation. If you take this exercise seriously, it can help you keep on top of much more challenging implementations. Thats part of what youre here to learn! This is what your program must do: 1. It must generate a randomized Sudoku problem to the console. The sudoku problem must have exactly 25 blanks. Your design from A2 is your guide. Thats why you did A2. 2. You must test various components of your program. Your testing depends on your design, but as a general rule, every function you implement (other than main) must be tested thoroughly, in main(). Your testing output must be readable by a third party (e.g., a marker, a colleague, a manager, a potential employer). Testing is up to you, and its purpose is to help you track down bugs and assure quality code, so it is not optional!
936-47258 825 93-6147 714 825-936 693 711525 582 693-71-4 471-5 82-593 3 6 9 4 7-15-82 2583-69-47 147 258-369
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
