Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python Please Question 8 Suppose that you have a triangular arrangment of integer values such as: You can move from a number down one layer
Python Please
Question 8 Suppose that you have a triangular arrangment of integer values such as: You can move from a number down one layer to a number immediately to the left or right (for example, you can move from 1 to 5 or -2, but not to 4). Each number that you move to incurs a cost equal to the number. You want to find the lowest cost of a path from the top of the triangle to the bottom of the triangle. In the triangle shown above, there are 4 paths having costs: . 9+1+5 - 15 . 9+1+(-2) = 8 . 9+(-3)+(-2) = 1 .9+(-3) + 4 = 10 so the lowest cost path has a cost of 4. To represent the triangular arrangment of values we will use a list of n sublists similar to that returned by the to_triangular_grid function from the previous question. For example, the triangle of numbers shown above is represented by the list: t - 119, -3, 4, 11, -21, (5 The top-most number of the triangle is given by t[0][0]. Write the function triangle coat impl(t, 1, 1) that recursively computes the lowest cost path to the bottom of the triangle starting at t[1][1] . Note that there is no upper limit on the height of the triangle. You should not call the function triangle_cost_impl directly; instead call the function triangle_cost(t) which returns the value of triangle_cost_implit, 0, 0). See the assignment module a3 where triangle_cost(t) is already given to you A few more examples of triangular arrangment of values and their lowest cost paths are given below: 3 t = [[3]] cost = a3.triangle_cost(t) # should be 3 (path 3) 1 3 2 t = [[1, 2], [3]] cost = a3.triangle_cost(t) # should be 3 (path 1, 2) 7 4 0 -5 -3 6 3 -2 -1 5 t = [[7, 0, 6, 5], [4, -3, -1], [-5, -2], [3]] cost = a3.triangle_cost(t) # should be 2 (path 7, 0, 6, -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