Answered step by step
Verified Expert Solution
Question
1 Approved Answer
the first photo shows Q1 now I want to solve the greedy_path use python greedy_path([[0,0,-150,0],[0,1000,0,0],[-1000,0,-1000,0],[0,0,150,0]]) >>> ([(0, 0), (1, 1), (2, 1), (3, 1), (3,
the first photo shows Q1 now I want to solve the greedy_path
use python
greedy_path([[0,0,-150,0],[0,1000,0,0],[-1000,0,-1000,0],[0,0,150,0]]) >>> ([(0, 0), (1, 1), (2, 1), (3, 1), (3, 2), (3, 3)], 1000) greedy_path([[0, -1000, 150, 150, 150], [1000, 0, 0, -150, 150], [0, -1000, 0, 0, 150], [0, -1000, -1000, -1000, 150], [1000, 1000, 1000, 1000, 0]]) >>> ([(0, 0), (0, 1), (1, 1), (2, 1), (2, 2), (3, 2), (4, 2), (4, 3), (4, 4)], 1300)
3. You do not need to visit each cell (such as traps). 4. There may be an item or trap on the goal. Please note that the above assumptions 1 - 3 are solely relevant to this particular task only. Assumption 4 will be present throughout all the questions. Eve will always travel from the cave entrance to the goal, so items or traps on the goal (assumption 4) must still be taken into account. The parameters to this function are as follows: matrix is a list of lists, where the "outer lists" denote rows and "inner lists" denote columns. Each cell is given an integer value denoting the "score" in the cell. Input Assumptions: You can assume that the input arguments are syntactically correct given the definitions, and will always be non-empty (i.e a minimum grid size of 1 x 1). Here are example calls to your function: dream_score([[0, -1000, 0, 0, 0], [0, 0, 150, 0, -1000] >>> 3150 dream_score([[0, 150, 150, 150], [150, 150, 150, 150], [: >>> 2250 dream_score([[, 0, 0], [0, -1000, 0], [-150, 0, 0]]) >>> 0 Write a function greedy_path(matrix) that takes in the same grid as Q1, and returns: 1. The locally optimal path using a "Best First Search" strategy as a list of tuples (coordinates). 2. The total score as an integer. Your function should return the above the result as a tuple in form (path, score). The parameters to this function are as follows: matrix is a list of lists, where the "outer lists" denote rows and "inner lists" denote columns. Each cell is given an integer value denoting the "score" in the cell. Note, that you are encouraged to make any additional helper function(s) to make your code become readable and neat (as there are marks awarded to this criteria). We also strongly suggest you draw out the grid and "mimic" a Best First Search before you write the code prior to implementing. Here's an example call to your function: greedy_path([[0, 0, -150,0], [0,1000,0,0],[-1000,0,-1000,0] >>> ([(0, ), (1, 1), (2, 1), (3, 1), (3, 2), (3, 3)], 11 greedy_path([[0, -1000, 150, 150, 150], [1000, 0, 0, -151 >>> ([(0, ), (0, 1), (1, 1), (2, 1), (2, 2), (3, 2), (4 greedy_path([[0, 1000, -1000, 0, 150, 150, 150], [1000, 1000, -1000, 0, -150, -150, -150], [1000, -1000, -1000, 0, 0, 0, 0], [1000, -1000, 0, 0, 0, 0, 0], [1000, -1000, 0, 0, 0, 0, 0], [1000, -1000, 0, 0, 0, 0, 0], [1000, 1000, 1000, 1000, 1000, 1000, -150]]) >>> ([(0, 0), (1, 0), (1, 1), (2, 1), (3, 1), (3, 2), (4 3. You do not need to visit each cell (such as traps). 4. There may be an item or trap on the goal. Please note that the above assumptions 1 - 3 are solely relevant to this particular task only. Assumption 4 will be present throughout all the questions. Eve will always travel from the cave entrance to the goal, so items or traps on the goal (assumption 4) must still be taken into account. The parameters to this function are as follows: matrix is a list of lists, where the "outer lists" denote rows and "inner lists" denote columns. Each cell is given an integer value denoting the "score" in the cell. Input Assumptions: You can assume that the input arguments are syntactically correct given the definitions, and will always be non-empty (i.e a minimum grid size of 1 x 1). Here are example calls to your function: dream_score([[0, -1000, 0, 0, 0], [0, 0, 150, 0, -1000] >>> 3150 dream_score([[0, 150, 150, 150], [150, 150, 150, 150], [: >>> 2250 dream_score([[, 0, 0], [0, -1000, 0], [-150, 0, 0]]) >>> 0 Write a function greedy_path(matrix) that takes in the same grid as Q1, and returns: 1. The locally optimal path using a "Best First Search" strategy as a list of tuples (coordinates). 2. The total score as an integer. Your function should return the above the result as a tuple in form (path, score). The parameters to this function are as follows: matrix is a list of lists, where the "outer lists" denote rows and "inner lists" denote columns. Each cell is given an integer value denoting the "score" in the cell. Note, that you are encouraged to make any additional helper function(s) to make your code become readable and neat (as there are marks awarded to this criteria). We also strongly suggest you draw out the grid and "mimic" a Best First Search before you write the code prior to implementing. Here's an example call to your function: greedy_path([[0, 0, -150,0], [0,1000,0,0],[-1000,0,-1000,0] >>> ([(0, ), (1, 1), (2, 1), (3, 1), (3, 2), (3, 3)], 11 greedy_path([[0, -1000, 150, 150, 150], [1000, 0, 0, -151 >>> ([(0, ), (0, 1), (1, 1), (2, 1), (2, 2), (3, 2), (4 greedy_path([[0, 1000, -1000, 0, 150, 150, 150], [1000, 1000, -1000, 0, -150, -150, -150], [1000, -1000, -1000, 0, 0, 0, 0], [1000, -1000, 0, 0, 0, 0, 0], [1000, -1000, 0, 0, 0, 0, 0], [1000, -1000, 0, 0, 0, 0, 0], [1000, 1000, 1000, 1000, 1000, 1000, -150]]) >>> ([(0, 0), (1, 0), (1, 1), (2, 1), (3, 1), (3, 2), (4Step 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