Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program In C, Write a program sudoku that (part 1) checks whether a proposed Sudoku solution is correct and (part 2) checks whether

Write a program In C, Write a program sudoku that (part 1) checks whether a proposed Sudoku solution is correct and (part 2) checks whether a partially-solved Sudoku puzzle with one unknown square can be solved. sudoku takes a single argument, which is the path to a le containing a completed or almost-completed Sudoku puzzle. A completed Sudoku puzzle is a 99 matrix containing the digits 19, inclusive. The matrix is divided into nine 33 submatrixes, themselves arranged in a 33 square. A completed Sudoku puzzle is a correct solution if and only if it has the following properties: Each digit occurs exactly once in each row (that is, no row contains any digit more than once. Each digit occurs exactly once in each column. Each digit occurs exactly once in each submatrix.An almost-completed Sudoku puzzle is similar, except that one or two elements are unspecied. This problem has two parts. For part one (6 points), you must be able to check whether a completed Sudoku puzzle contains a correct solution. For part two (6 points), you must be able to determine whether an almost-completed Sudoku puzzle is solvable. The remaining 4 points are for style. Both parts are submitted as a single program. You will receive partial credit if your program correctly handles part one. 1.7.1 Correctness checking The input le contains a completed Sudoku puzzle. The puzzle is given on nine lines, each of which contains nine digits without any separation. Note that the digit 0 will not occur. The input le file1.txt corresponding to the puzzle above would contain:

534678912

672195348

198342567

859761423

426853791

713924856

961537284

287419635

345286179

When given such a le, sudoku must determine whether the completed puzzle is a correct solution (meaning it satises the three properties). If so, it prints correct. Otherwise, it prints incorrect. If the input le does not exist, is not readable, or does not follow the format specied here, sudoku may print error. Usage $ ./sudoku file1.txt

correct

1.7.2 Solvability checking The input le contains an almost-completed Sudoku puzzle. The format is the same as abovenine lines with nine characters eachexcept that up to two of the characters may be spaces instead of digits. The spaces indicate that the digit for that element is unspecied. The input le file2.txt contains an almost-completed puzzle with two unknown entries: 435269781

682571493

1978345 2

26195347

374682915

951743628

519 26874

248957136

763418259 If the input le contains an almost-completed puzzle, sudoku must determine whether the puzzle can be solved. If the puzzle has unspecied entries, can they be replaced by a digits such that the completed puzzle is a correct solution? If so, sudoku prints solvable. Otherwise, it prints unsolvable. If the puzzle contains no unspecied entries (that is, it is a completed puzzle), sudoku will print correct or incorrect as before. If the input le does not exist, is not readable, does not follow the format specied above, or contains more than two unspecied elements, sudoku may print error. Usage $ ./sudoku file2.txt

solvable

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

6. Explain the strengths of a dialectical approach.

Answered: 1 week ago