Question: help with these functions on python Is_valid_cage_solution (puzzle, op, expected_total, locations): given a puzzle, an operation op, an integer expected_total, and a list of location
help with these functions on python

Is_valid_cage_solution (puzzle, op, expected_total, locations): given a puzzle, an operation op, an integer expected_total, and a list of location tuples(e.g. a "cage" in a KenkKen puzzle), determine if the puzzle locations total correctly for the operation. You do not need to check if the rows/columns of the puzzle are valid. Assumptions: the puzzle is complete the operation will be one of: ' +, or ' x' subtraction operations will always involve two (and only two) locations subtraction operations pass in the absolute value of the operation (see examples) the locations will be valid and in a list in the form: [(row, col), (row, col), (row, col)] Examples: is_valid_cage_solution([[1]], ' + 1, [(theta, theta)]) rightarrow True # location (0, 0) sums to 1 is_valid_cage_solution([[1, 2], [2, 1]], 1, [(0, 0), (1, 0)]) rightarrow True # the absolute value of location (0, 0) - location (1, 0) is 1 is_valid_cage_solution([[l, 2], [2, l]], '1, [(1, 0), (0, 0)]) rightarrow True # the absolute value of location (1, 0) - location (0, 0) is 1 is_valid_cage_solution([[1, 2], [2, 1]], 'x', 4, [(0, 0), (0, 1), (1, 0), (1, 1)]) rightarrow True # all values in the puzzle multiplied together = 4 is_valid_cage_solution([[1, 1], [1, 1]], 'x', 1, [(0, 0)]) rightarrow True # location (0, 0) multiplies to 1 is_valid_cage_solution([[1, 2], [2, 1]], 4, [(0, 0), (0, 1)]) rightarrow False # location (0, 0) and (0, 1) do not sum to 4 is_valid(puzzle, cages, complete): determine if the given puzzle is currently in a valid state: if incomplete, check whether all rows/columns are valid, if complete also check cages and determine if the puzzle locations total correctly for the operation. board_l = [[3, 1, 2], [2, 3, 1], [1, 2, 3]] board_2 = [[3, 1, 2], [2, 2, 1], [1, 2, 3]] is_valid(board_l, [], False) rightarrow True is_valid(board_l, [['+', 5, [(0, 0), (1, 0)]]], True) rightarrow True is_valid(board_l, [['+', 4, [(0, 0), (1, 0)]]], True) rightarrow False # not valid cage is_valid(board_2, [['+', 5, [(0, 0), (1, 0)]]], True) rightarrow False # invalid row is_valid([[None, None], [None, None]], [[+', 5, [(0, 0), (1, 0)]]], False) rightarrow True Is_valid_cage_solution (puzzle, op, expected_total, locations): given a puzzle, an operation op, an integer expected_total, and a list of location tuples(e.g. a "cage" in a KenkKen puzzle), determine if the puzzle locations total correctly for the operation. You do not need to check if the rows/columns of the puzzle are valid. Assumptions: the puzzle is complete the operation will be one of: ' +, or ' x' subtraction operations will always involve two (and only two) locations subtraction operations pass in the absolute value of the operation (see examples) the locations will be valid and in a list in the form: [(row, col), (row, col), (row, col)] Examples: is_valid_cage_solution([[1]], ' + 1, [(theta, theta)]) rightarrow True # location (0, 0) sums to 1 is_valid_cage_solution([[1, 2], [2, 1]], 1, [(0, 0), (1, 0)]) rightarrow True # the absolute value of location (0, 0) - location (1, 0) is 1 is_valid_cage_solution([[l, 2], [2, l]], '1, [(1, 0), (0, 0)]) rightarrow True # the absolute value of location (1, 0) - location (0, 0) is 1 is_valid_cage_solution([[1, 2], [2, 1]], 'x', 4, [(0, 0), (0, 1), (1, 0), (1, 1)]) rightarrow True # all values in the puzzle multiplied together = 4 is_valid_cage_solution([[1, 1], [1, 1]], 'x', 1, [(0, 0)]) rightarrow True # location (0, 0) multiplies to 1 is_valid_cage_solution([[1, 2], [2, 1]], 4, [(0, 0), (0, 1)]) rightarrow False # location (0, 0) and (0, 1) do not sum to 4 is_valid(puzzle, cages, complete): determine if the given puzzle is currently in a valid state: if incomplete, check whether all rows/columns are valid, if complete also check cages and determine if the puzzle locations total correctly for the operation. board_l = [[3, 1, 2], [2, 3, 1], [1, 2, 3]] board_2 = [[3, 1, 2], [2, 2, 1], [1, 2, 3]] is_valid(board_l, [], False) rightarrow True is_valid(board_l, [['+', 5, [(0, 0), (1, 0)]]], True) rightarrow True is_valid(board_l, [['+', 4, [(0, 0), (1, 0)]]], True) rightarrow False # not valid cage is_valid(board_2, [['+', 5, [(0, 0), (1, 0)]]], True) rightarrow False # invalid row is_valid([[None, None], [None, None]], [[+', 5, [(0, 0), (1, 0)]]], False) rightarrow True
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
