Menu
support@authoritypapers.com
+1(805) 568 7317

s 0 0 7 0 0 0 0 1 5 0 0 0 3 9 7 0 0 0 0 6 2 0 1 0 4 0 9 0 2 0 0 0 1 5 4 3 7 5154371

Question 4 - Applying Strategies (4 points) Now that we have a strategy to apply (elimination), we should teach the computer

s = [[0,0,7, 0,0,0, 0,1,5],
[0,0,0, 3,9,7, 0,0,0],
[0,6,2, 0,1,0, 4,0,9],
[0,2,0, 0,0,1, 5,4,3],
[7,0,0, 4,0,9, 0,0,1],
[4,8,1, 2,0,0, 0,6,0],
[9,0,6, 0,2,0, 7,3,0],
[0,0,0, 9,8,4, 0,0,0],
[1,5,0, 0,0,0, 2,0,0]
]

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

s5=[[0,0,7, 0,0,0, 0,1,5],
[0,0,0, 3,9,7, 0,0,0],
[0,6,2, 0,1,0, 4,0,9],
[6,2,9, 0,7,1, 5,4,3],
[7,3,5, 4,6,9, 8,2,1],
[4,8,1, 2,0,0, 9,6,7],
[9,4,6, 0,2,5, 7,3,8],
[0,7,3, 9,8,4, 0,5,6],
[1,5,8, 0,3,6, 2,9,4]]

The elimination code I have is

def elimination(x, y, s):
print('Value: ', s[x][y])
possibleVals = []
for val in range(1, 10):
possible = subSquareCheck(x, y, val, s)
if possible:
for i in range(9):
if s[x][i] == val:
possible = False
if possible:
for i in range(9):
if s[i][y] == val:
possible = False
if possible:
possibleVals.append(val)
if len(possibleVals) == 1:
return possibleVals[0]
elif len(possibleVals) > 1:
return 0
else:
raise Exception(“Sudoku Invalid”)

Question 4 – Applying Strategies (4 points) Now that we have a strategy to apply (elimination), we should teach the computer how to apply strategies to a sudoku puzzle. However, the elimination strategy sonly one of a number of possible sudoku solving strategies. For more information on sudoku solving strategies, take a look at the following youtube video: https://www.youtube.com/watch?v=b123EURtu3l . With respect to this video, we have only implemented somewhat dubiously named “Naked Singles” strategy. Write a function 'applyStrategy(strategy, s)' which, given a strategy (in this case, a function with the input/output properties described in Question 3), and a puzzle s, applies that strategy to each cell in the puzzle. Have the function return True if the strategy worked, and False if it didnt (see below). It will become important later on to know if a strategy worked. To this end, we need to keep track of whether there are any differences between the strategy's return results and what was already in the puzzle. To clarify, if, for a particular cell, the strategy returns what the cell already contained, there has been no change, and the strategy failed for that cell. We are interested in whether at least one of the cells were changed when we applied the strategy to the entire puzzle. HINT: There is no need to run a strategy on cell that is not “blank” (i.e., contains zero). DOUBLE HINT: Given that s is a mutable data type, we can simply modify the contents of the cells using assignment statements. In def applystrategy(strategy, s) : return False YOUR CODE HERE Test Cases In [instantiateCases ) applyStrategy (el imination, s) S S5 In instantiateCases () applystrategy (elimination, s3) == False

"Order a similar paper and get 15% discount on your first order with us
Use the following coupon
"GET15"

Order Now