Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3 Coding: I have make empty board completed but not the others. Any help is appreciated. We are going to implement a series of

image text in transcribedPython 3 Coding: I have make empty board completed but not the others. Any help is appreciated.

We are going to implement a series of functions that allows us to build up and validate solutions of KenKen puzzles of any size. The first few functions should be relatively easy, some are just warmups, others might be useful building blocks to use (call) in later function definitions. All parameters named puzzle or cage are assumed to be as defined above in our definitions section. Make_empty_board(n): make an "empty" n by n board. Empty boards are filled with None. Assume n > 0. make_empty_board(1) rightarrow [[None]] make_empty_board (2) rightarrow [[None, None], [None, None]] make_empty_board (4) rightarrow [None, None, None, None] [None, None, None, None] [None, None, None, None] [None, None, None, None]] is_valid_location (loc, puzzle): given a location as a tuple (row, col) determine if those coordinates are valid locations in the puzzle. You do not need to check if value is valid is valid is_valid_location ((1, 1), [[None]]) rightarrow False is_valid_location, ((1, 1), [[1, 2], [2, 11]) rightarrow True # 2 times 2 puzzle ha a row 1 and col 1 is_valid_location ((1, 2), [[1, 2], [2, 1]]) rightarrow False # 2 times 2 puzzle has a row 1, but not a col 2 is_complete(puzzle): determine if the puzzle has any remaining None locations. You do not need to check if the puzzle is a valid solution is_complete ([[1, 2, 31, [3, 1, 2], [2, 3, 11]) rightarrow True is_complete ([[1, 1, 1], [1, 1, 1], [1, 1, 11]) rightarrow True is_complete ([1, 2] [None, 1]]) rightarrow False is_complete ([[None, None], [None, None]]) rightarrow False get_value_at_location (puzzle, loc): given a location as a tuple (row col), return the value at that location of the given puzzle. You may assume that the location provided is a valid location. get_value_at_location ([[1] (0,0)) rightarrow 1 get_value_at_location ([[1, 2], [None, 1] (1,0)) rightarrow None get_value_at_location ([1, 2], [2, 1]], (1, 1) rightarrow 1 ([[1, 2, 31, [2, 3, 1], [3, 1, 21], (2, 1)) rightarrow 1 set_locaction(puzzle, value, loc): given a puzzle, a value, and a location (row col), try to set the set location (puzzle puzzle location to that value. If the puzzle location is empty, set the value and return True. If the location is already set, or the location is invalid, do not modify the puzzle and return False. You do not need to check if value is valid. set_locaction ([[1]], 1, (0,0) rightarrow False set_locaction ([[None]], 1, (0,0) rightarrow True # puzzle is now [11] set_locaction ([[None]], 1, (1,0) rightarrow False # invalid location set_locaction ([[None]], 3, (0,0)) rightarrow True # puzzle is now [[3]] set_locaction ([[1, 2], [None, 1]], 2, (1,0)) rightarrow True # puzzle is now [[1, 2], [2, 1]]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions