Question
crate function grids_augmented_with_number(grid,num) that returns a list of valid n n grids, where each grid contains n nums. (I.e. if given a 9 9 grid,
crate function grids_augmented_with_number(grid,num) that returns a list of valid n n grids, where each grid contains n nums. (I.e. if given a 9 9 grid, and num = 3, each grid returned must contain nine 3's.)
Input: a nested list grid, that represents a valid n n sudoku grid; each item in the inner list is either an integer (example 13), or the string 'x'; and a positive integer num, where 0 < num n.
Output: a nested list containing all valid sudoku grids where each grid contains n nums. If there is no way to augment the given grid to create valid sudoku grid containing n nums, return an empty list. 5
Examples
lite_grid = [[1,'x','x','x'],['x','x','x','x'],['x','x','x','x'],['x',2,'x','x'],]
full_grid = [[2,'x','x','x'],['x',3,2,4],['x','x',4,2],[1,2,3,'x'],]
grid_A = [['x','x',1,'x'],[4,'x','x','x'],['x','x','x',2],['x',3,'x','x'],]
a) Calling grids augmented with number(lite grid,1) returns: [ #note there are now 1s in every row, column, and inner square in both grids [ [1,'x','x','x'], ['x','x',1,'x'], ['x',1,'x','x'], ['x',2,'x',1] ] , [ [1,'x','x','x'], ['x','x','x',1], ['x',1,'x','x'], ['x',2,1,'x'] ] ]
b) Calling grids grids_augmented_with_number(full grid,1) returns [], because there is no valid way to modify full grid so that it contains four 1s.
c) Calling grids grids_augmented_with_number(grid A,1) returns: [ [ ['x','x',1,'x'], [4,1,'x','x'], [1,'x','x',2], ['x',3,'x',1] ] ]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started