Question: 1. Sudoku solution checker. Write a python program (called q1.py) that determines whether a Sudoku solution is valid or invalid. In Sudoku, the objective is
1. Sudoku solution checker. Write a python program (called q1.py) that determines whether a Sudoku solution is valid or invalid. In Sudoku, the objective is to fill a 99 grid with digits so that each row, each column, and each of the nine 33 blocks contains all of the digits from 1 to 9 (see Figure 1 below).
546893217
392174685
817526934
769341852
234785196
185269743
458612379
921437568
673958421
Figure 1: Sudoku Solution
The solution will be stored in a file containing 9 lines, where each line represents the solution for a row. For example, consider the file soln1.txt below, which contains the solution for the puzzle shown in Figure 1.
soln1.txt
1 546893217
2 392174685
3 817526934
4 769341852
5 234785196
6 185269743
7 458612379
8 921437568
9 673958421
Since soln1.txt represents a valid solution, your program will output Valid solution. If a solution is invalid, your program will output Invalid solution.
Your objective. Sample code has been provided for you in q1.py. The provided code (i) asks the user for a file, (ii) stores the data from the file in a nested tuple of tuples, and (iii) prints the results. Your job is to write the remaining pieces of the code to verify the solution by checking the nine rows, nine columns, and nine 3x3 blocks. Thus, the functions you will write are valid_rows(soln), valid_cols(soln), and valid_blocks(soln), respectively.
Several files have been provided to test your program. But, you should also create your own test files to test the correctness of your code. Also, pay attention to the comments in the provided code.
Programming tips. For each function, print the contents of the variable soln (which is a nested tuple of tuples) to see the data you are manipulating. Next, draw a picture of the soln data structure before writing your code. Once you understand how the data is organized, you are ready to write the code.
Example #1. The user enters the name of the Sudoku solution file (line 1). The program then determines that the soln1.txt file is a valid Sudoku solution (line 3).
1 Enter filename: soln1.txt
2
3 Valid Solution
Example #2. The user enters the name of the Sudoku solution file (line 1). The program then determines that the soln3.txt file is an invalid Sudoku solution (line 3).
1 Enter filename: soln1.txt
2
3 Invalid Solution
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
