tp.txt ideas for Amy's CS 150 test project S20 inspired by Google code jam qualification round 2020, problem A, Vestigium Daniel Scharstein 4/27/2020 Mudoku For this test project, let's consider "Mudokus" (a simple variant of sudokus), which are N x N squares in which each row and each column contain the numbers 1 through N. For example, here's as valid 3 x 3 mudoku: A. 3 2 1 2 1 3 1 3 2 And here's a valid 4 x 4 mudoku: B. 1 2 3 4 2 3 4 1 4 1 2 3 3 4 1 2 (In case you're familiar with regular sudokus, note that in here we don't have the notion of small sub-blocks.) Here are examples of N x N grids that are NOT mudokus, together with the reason why: C. 1 2 3 2 3 4 3 1 2 * contains a number not in the range 1-3 D. 2 1 3 4 3 2 4 1 1 4 3 2 4 3 1 3 * contains the number 3 twice in column 3 and in row 4 In Python, we can represent such grids as lists of lists. For instance, the about examples could be stored as A = [[3, 2, 1], [2, 1, 3], [1, 3, 2]] B = [[1, 2, 3, 4], [2, 3, 4, 1], [4, 1, 2, 3], [3, 4, 1, 2]] C = [[1, 2, 3], [2, 3, 4], [3, 1, 2]] D = [[2, 1, 3, 4], [3, 2, 4, 1], [1, 4, 3, 2], [4, 3, 1, 3]] Problem 1: ---------- Write a function print_mudoku that takes a list representing an N x N mudoku and prints it as a grid. You may assume 2 <= N <= 9. Sample runs using the variables defined above: >>> print_mudoku(A) 3 2 1 2 1 3 1 3 2 >>> print_mudoku(B) 1 2 3 4 2 3 4 1 4 1 2 3 3 4 1 2 >>> print_mudoku(C) 1 2 3 2 3 4 3 1 2 >>> print_mudoku(D) 2 1 3 4 3 2 4 1 1 4 3 2 4 3 1 3 Problem 2 --------- Write a function is_mudoku that takes a list representing a mudoku and returns True if it is a valid mudoku, and false otherwise. You may define helper functions if you wish. Sample runs, given the variables define above: >>> is_mudoku(A) True >>> is_mudoku(B) True >>> is_mudoku(C) False >>> is_mudoku(D) False >>> is_mudoku([[1, 2], [2, 1]]) True >>> is_mudoku([[1, 2], [3, 4]]) False Problem 3 --------- Write a function reasons_not_mudoku that takes a list representing a mudoku and prints the reasons why it's not a valid mudoku. It should print sentences like the following, one for each violation: duplicate or values in row X duplicate values in column Y illegal value Z The order in which these lines are printed does not matter. If given a valid mudoku, the function should print nothing. Then, write a function check_mudoku that takes a mudoku and uses your previous functions to (1) print it, (2) print "is a valid mudoku" or "is NOT a valid mudoku:", and (3) print the reasons. Sample runs: >>> check_mudoku(A) 3 2 1 2 1 3 1 3 2 is a valid mudoku >>> check_mudoku(C) 1 2 3 2 3 4 3 1 2 is NOT a valid mudoku: illegal value 4 >>> check_mudoku(D) 2 1 3 4 3 2 4 1 1 4 3 2 4 3 1 3 is NOT a valid mudoku: duplicate values in column 3 duplicate values in row 4 >>> check_mudoku([[1, 2], [1, 2]]) 1 2 1 2 is NOT a valid mudoku: duplicate values in column 1 duplicate values in column 2 >>> check_mudoku([[1, 2], [3, 4]]) 1 2 3 4 is NOT a valid mudoku: illegal value 3 illegal value 4 >>> check_mudoku([[7, 2], [4, 4]]) 7 2 4 4 is NOT a valid mudoku: duplicate values in row 2 illegal value 4 illegal value 7 Note: in all problems, you may assume that the function is called with valid list of N lists containing N numbers each, with 2 <= N <= 9.