In Python Write a function to read a Sudoku board from an input string. The input string must...

50.1K

Verified Solution

Question

Programming

In Python

Write a function to read a Sudoku board from an inputstring.

The input string must be exactly 81 characters long (plusthe

terminating null that marks the end of the string) andcontains

digits and dots (the `.` character represents an unmarkedposition).

The input contains all 9 rows packed together. For example, aSudoku

board that looks like this:

```

..7 ... ...

6.4 ... ..3

... .54 ..2

... .4. ...

9.. ... ..5

385 ..2 ...

... ..3 78.

49. 71. ...

1.. ..8 9..

```

would be input as the string

```

\"..7......6.4.....3....54..2....4....9.......5385..2........378.49.71....1....89..\"

```

The function must read the board into an array of 81 bytes, withthe

value 0 (*not* the digit `'0'`) for unfilled positions(represented

by dots in the input) and the values 1 through 9 (*not*the digits

`'1'` through `'9'`) for filled positions.

As it reads, the function should validate the input. If it istoo

short, it should return 1. If it encounters an invalidcharacter

(not a dot or a digit) then it should return 2. If the string istoo

long it should return 3.

The following pseudocode should form the basis of yourfunction:

Answer & Explanation Solved by verified expert
3.7 Ratings (307 Votes)
HERE We USES partially filled 99 2D array grid99 the goal is to assign digits from 1 to 9 to the empty cells so that every row column and subgrid of size 33 contains exactly one instance of the digits from 1 to 9 A Backtracking program in Python to solve Sudoku problem A Utility Function to print the Grid def printgridarr for i in range9 for j in range9 print arrij print n Function to Find the entry in the Grid that is still not used Searches the grid to find an entry that is still unassigned If found the reference parameters row col will be set the location that is unassigned and true is returned If no unassigned entries    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students