# WORKING WITH SUDUKO IN PYTHON 3: PLEASE ANSWER ALL PARTS TO THIS MULTISTEP PROBLEM AND INDICATE CORR

WORKING WITH SUDUKO IN PYTHON 3: PLEASE ANSWER ALL PARTS TO THIS MULTISTEP PROBLEM AND INDICATE CORRECT INDEXING

1a)

Write a function &#39;subSquareCheck(x,y,val,s)&#39; that, given the x and y position of the cell we are checking (&#39;x&#39; and &#39;y&#39; respectively), a value to check &#39;val&#39;, and a sudoku puzzle &#39;s&#39;, returns False if the given value has already been used in the indicated sub-square, and True if the number is still available.

HINT: Up to now we have been creating ranges to loop over within the loop statement itself, but this need not be the case! While it&#39;s certainly possible to generate the correct ranges algebraicly, you could also use if-statements!

ANOTHER HINT: In our sudoku format, the first index selects the row, which means it corresponds to the y-coordinate.

1b)

There are several strategies that may be used to solve a sudoku puzzle, but the simplest is the so-called “process of elimination.” Using this strategy, we examine a cell&#39;s environment to see how many numbers are possible. This should be reasonably simple, since the range of possible values is known, and we already have three functions which perform the three checks necessary.

If there is only one value that is allowable, then the value gets written into that cell. If there is more than one possibility, we leave the cell blank. If there are no possible values for this cell, then the information given in the puzzle contradicts the three rules of sudokus. In this case, we will raise a “Sudoku Invalid” exception.

Write a function &#39;elimination(x,y,s)&#39; that, given a zero-indexed x and y position in the puzzle (&#39;x&#39; and &#39;y&#39; respectively), and a sudoku puzzle s, returns the either a zero or “blank” if there is more than one possible answer, the answer if there is exactly one possible answer, and raises a “Sudoku Invalid” exception if there are no possible answers.

1c)

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 is only 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=b123EURtu3I . With respect to this video, we have only implemented somewhat dubiously named “Naked Singles” strategy.

Write a function &#39;applyStrategy(strategy, s)&#39; 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&#39;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 a 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.

1d) We must repeatedly apply the given list of strategies to the puzzle until they stop working or the puzzle is solved (remember to use our function from Question 1!) We will try to apply each strategy in the list of strategies once to the puzzle per execution of the loop. If all of them return False, the puzzle has not changed, and we break the loop. If the algorithm fails to solve the puzzle, raise a “Sudoku Unsolvable” exception. Otherwise, return the solved puzzle.