Sudoku Solved?

Sudoku Solved?

Below are a number of completed Sudoku puzzles. Two are correct. Two are incorrect. (I won't tell you which are which. ) Write me a program that distinguishes those that are solved correctly from those that are not. Print your conclusion. Like this: "Table 1 is correct (or incorrect). Table 2 is ... ". Etc.

How will you get the data from below into your program? Follow this link to a replit project. The data is contained in a file named "completed_puzzles.txt". I've generously written a function for you that reads the lines in that file into a list. Of course that's only a small bit of the work you'll have to do. I suggest that you convert the list of strings generated by the function I provided into multiple 2D integer lists, one for each puzzle. For instance, the list for Table 1 will begin [[8, 4, 5, 6, 3, 2, 1, 7, 9], [7, 3, 2, 9, 1, 8, 6, 5, 4], ... ]. Note that the character '\n' at then end of each string that's read in. That's a so-called escape sequence; it's the character representation of the end of a line. It counts as a single character, as can be seen below:

>>> len('\n')

1

Note as well that if you store a table as a 2D array, you'll have to double index to pull out a particular integer. Like this:

>>> L = [[8, 4, 5, 6, 3, 2, 1, 7, 9], [7, 3, 2, 9, 1, 8, 6, 5, 4]]

>>> L[0][0]

8

>>> L[0][1]

4

>>> L[1][0]

7

>>> L[1][1]

3

On the day the project is due, I'll give you another file of completed Sudoku puzzles, formatted precisely as below, and have you tell me which are solved correctly and which are not.

No doubt you'll write many functions. But one will be the master function - the only function that's called, the function that orchestrates the execution of all the others. Call this master function find_solved_sudoku. It will have just one parameter, the name of the text file from which the program will read. The only line of code that won't be contained in some function or other is find_solved_sudoku(file_name). When you hit the run button, it will call find_solved_sudoku and that function will take over from there.

A final word. Try to make each of your functions single-task. Moreover, think carefully before you begin to code about what tasks need to be carried out; and as you write your code, aim to place each task in its own function. One central task, of course, is to determine whether a sequence of 9 integers contains all of 1 through 9. I'd certainly make that it's own function. So here's how you might structure your code:


Below are the tables in the project I began for you:

Table 1

8 4 5 | 6 3 2 | 1 7 9

7 3 2 | 9 1 8 | 6 5 4

1 9 6 | 7 4 5 | 3 2 8

---------------------

6 8 3 | 5 7 4 | 9 1 2

4 5 7 | 2 9 1 | 8 3 6

2 1 9 | 8 6 3 | 5 4 7

---------------------

3 6 1 | 4 2 9 | 7 8 5

5 7 4 | 1 8 6 | 2 9 3

9 2 8 | 3 5 7 | 4 6 1


Table 2

2 5 6 | 8 3 1 | 7 4 9

8 3 7 | 6 4 9 | 5 1 2

1 9 4 | 7 2 5 | 3 8 6

---------------------

6 4 1 | 5 8 7 | 9 2 8

7 2 5 | 1 9 3 | 8 6 4

3 8 9 | 4 6 2 | 1 7 5

---------------------

9 7 8 | 2 5 4 | 6 3 1

5 6 2 | 3 1 8 | 4 9 7

4 1 3 | 9 7 6 | 2 5 3


Table 3

8 5 7 | 2 6 1 | 3 9 4

3 1 2 | 4 9 5 | 7 8 6

9 6 4 | 3 7 8 | 2 1 5

---------------------

1 9 5 | 7 3 4 | 6 2 8

7 2 8 | 9 5 6 | 1 4 3

6 4 3 | 1 8 2 | 5 7 9

---------------------

5 8 1 | 6 4 7 | 9 3 2

4 7 9 | 5 2 3 | 8 6 1

2 3 6 | 8 1 9 | 4 5 7


Table 4

1 2 5 | 6 4 9 | 3 7 8

8 3 4 | 7 1 5 | 2 9 6

6 9 7 | 3 8 2 | 4 1 5

---------------------

7 4 6 | 9 5 3 | 1 8 2

3 5 9 | 8 2 1 | 7 6 4

2 8 1 | 7 4 6 | 9 5 3

---------------------

5 7 3 | 2 9 8 | 6 4 1

4 6 8 | 1 3 7 | 5 2 9

9 1 2 | 5 6 4 | 8 3 7


EoF