Answered step by step
Verified Expert Solution
Question
1 Approved Answer
WRITE THE FOLLWING PROGRAM IN PYTHON: In this puzzle, you are given a grid of numbers, presented as a list of lists. the number in
WRITE THE FOLLWING PROGRAM IN PYTHON:
In this puzzle, you are given a grid of numbers, presented as a list of lists. the number in each grid square tells you how many steps you can move in one direction. For example, from a square with a number 2, you can move two squares up, two squares down, two square right, or two squares left. The goal, like in a maze is get from a start position to an end position Represent the Puzzle When dealing with a list of lists, if can get a little confusing about how to access individual elements If we have L [ [1,2] , 3,4] , then L [0] [1] is 2 . The first index is the row, starting from zero. Increasing this index moves down the grid (this is also how matrices are indexed). The second index is the column number, starting at zero. As a result, it makes sense to indicate a position in the grid using a tuple (r, c), where r is the row and c is the column We will build a puzzle class with the following ADT onboard(position) return True if the (r,c)-pair position is within the bounds of the grid Return False otherwise __getitem__(position)-return the number stored in the (r,c)-pair position rdsolve(start, end) return True if it is possible to get from the position start to the position end using only right and down moves. Return False otherwise solve(start, end) return True if it is possible to get from the position start to the position end. Return False otherwise. Start by writing a class called Puzzle and store it in a file called puzzle.py .Write an_init method that takes a list of lists of integers. It should store these lists internally. The initializer should raise ValueError if the lists do not all have the same length (only rectangular puzzles are allowed). Next, implement the onboard method to check if a given row and column (given as a tuple of ints) is within the bounds of the input listsStep 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