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,...
View the step-by-step solution to:

Question

Please solve in Python Numpy:

Screen Shot</h1><p class='abPRemoveTitle'> 2019-10-01 at 9.36.11 PM.png

Screen Shot 2019-10-01 at 9.36.26 PM.png

Screen Shot 2019-10-01 at 9.36.40 PM.png

Screen Shot 2019-10-01 at 9.36.48 PM.png

Reference Code from Implementation Notes:

Screen Shot 2019-10-01 at 9.37.12 PM.png

Screen Shot 2019-10-01 at 9.36.11 PM.png

. 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 &quot;OK! &quot;. If not, the errors are enumerated, again by printing.
Here's a correct board:
&gt;&gt;&gt; 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
&gt; &gt; &gt; type(bl)
&lt;class 'str &gt;
&gt;&gt;&gt; check_sdk (make_board(bl ) )
OK!

Screen Shot 2019-10-01 at 9.36.26 PM.png

Here's a board with a single digit that's wrong:
&gt;&gt;&gt; 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
&gt; &gt;&gt; type (b2 )
&lt;class 'str'&gt;
&gt;&gt;&gt; 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!

Screen Shot 2019-10-01 at 9.36.40 PM.png

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:
&gt;&gt;&gt; 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
&gt;&gt; &gt; type (b3)
&lt;class 'str'&gt;
&gt;&gt;&gt; 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)

Screen Shot 2019-10-01 at 9.36.48 PM.png

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.

Screen Shot 2019-10-01 at 9.37.12 PM.png

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 = [&quot;534678912&quot;
&quot;672195348&quot; ,
&quot;198342567&quot;
&quot;859761423&quot;
&quot;426853791&quot;,
&quot;713924856&quot;,
&quot;961537284&quot;,
&quot;287419635&quot;
&quot;345286179&quot;]
board = np. empty (shape=(9,9) , dtype=&quot;int8&quot;)
for r in range (9) :
for c in range (9) :
board [r, c] = init[r] [c]
return board

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes