__Please solve in Python Numpy:__

__Reference Code from Implementation Notes:__

Image transcriptions

. check_sdk: (24 points) During lecture we worked on a partial Sudoku checker. For this problem you're to develop a full checker, handling rows, columns, and squares. check_sdk takes one argument, a 9x9 array of integers that represents a Sudoku board and checks to see if each row, column, and 3x3 square (non-overlapping) contain each of the digits from 1-9. If that's true, check_sdk prints "OK! ". If not, the errors are enumerated, again by printing. Here's a correct board: >>> print(bl) W 4 6 7 8 9 6 2 195 1 3 4 JOO N - OOOHNUI - + + 9 HIWON 7 6 IUW 8 9 2 8 + + 9 6 5 3 2 7 4 ONIPWHIN 1 9 3 4 5 2 8 6 HONI TWOJUNIORH BUTIGHWI > > > type(bl) <class 'str > >>> check_sdk (make_board(bl ) ) OK!

Here's a board with a single digit that's wrong: >>> print(b2) - w 4 6 91 2 2 1 5 3 8 9 8 3 4 2 67 IPNUI -IWOI + - - - + - 3 8 5 3 N 4 - + NIDNAIU UNI 6 + - - 8 61 5 3 7 8 4 287 4 19 6 W 4 5 2 8 6 1 > >> type (b2 ) <class 'str'> >>> check_sdk (make_board(b2 ) ) Bad row(s) : 7 Bad column (s) : 1 Bad square (s) : (7, 1) Notice that the errors report the row and column numbers, and the coordinates of the upper left-hand corner of squares, using one-based numbering, just like non-programmers do!

Notice that the errors report the row and column numbers, and the coordinates of the upper left-hand corner of squares, using one-based numbering, just like non-programmers do! Here's a board with several mistakes: >>> print(b3) 5 3 4 6 7 8 6 2 195 3 4 198 3 4 2 6 - - - + - - + 8 9 6 -I Wa 8 9 NU + - - I FWH + 9 9 43 2 8 7 1 2 2 3 4 5 2 1 2 HOWIONAIU JWOOIMINI URIAHWI JON >> > type (b3) <class 'str'> >>> check sdk (make_board(b3) ) Bad row(s) : 7 8 9 Bad column (s) : 4 5 6 7 Bad square (s) : (7, 4) (7, 7)

Implementation notes: The zip you download from D2L will include make_board . py, which has code for the make_board function. Copy the code for make_board into your a4 . py. My check sdk function uses three helper functions: check_rows, check_squares, and check 19. check_squares is very much like the partial checker we worked on in class. check_19 is a boolean function that returns True iff an array contains exactly the integers from one through nine. I was about to write a check_cols function, too, but then I realized that check rows could be called twice, once to check rows and then again to check columns. (Think about it!) I really should have cast this problem as a Board class with a check method but that didn't cross my mind until it was too late. However, it would surely be good practice for the first mid-term to do that on your own.

def check (board) : correct = list (range (1, 10) ) for r in range (0, 9,3): for c in range (0, 9,3): square = board [r:r+3, c:c+3] if sorted ( square. flatten () ) != correct: return (r, c) return True def make_board ( ) : # From Wikipedia init = ["534678912" "672195348" , "198342567" "859761423" "426853791", "713924856", "961537284", "287419635" "345286179"] board = np. empty (shape=(9,9) , dtype="int8") for r in range (9) : for c in range (9) : board [r, c] = init[r] [c] return board

**321,403 students got unstuck** by Course

Hero in the last week

**Our Expert Tutors** provide step by step solutions to help you excel in your courses