Question
PYTHON Im stuck on this problem, PLEASE HELP! and please follow the implementation requirements! THANK YOU!...
PYTHON Im stuck on this problem, PLEASE HELP! and please follow the implementation requirements! THANK YOU!
Implement an efficient python function for the following: def find_Number_of_A11_Possible_Ways(matrix, totalGasAmount): The above function will count all the possible paths from top left cell to bottom right cell of a matrix using exactly totalGasAmount. Each cell of this matrix has a nonnegative number which represents gas amount of that cell. The constraint is that from each cell, you can either move right or move down and you have to use that amount of Gas for moving. Example Input 1: matrix = [ (1, 3, 2, 1], [10, 11, 16, 2], [23, 30, 34, 3] find_Number_of_A11_Possible_Ways (matrix, 12) 1 #1 way to reach destination Explanation: 1 way to reach destination #[right right,right,down, down] and cost is 1+3+2+1+2+3 = 12 Example Input 2: matrix = [ [1, 3, 8, 7] [10, 1, 6, 20), [23, 30, 2, 5] 3 find_Number_of_A11_Possible_Ways (matrix, 25) 2 #2 ways to reach destination
matrix = [. [1, 3, 8, 71, [10, 1, 6, 20). [23, 30, 2, 5] ] find_Number_of_All_Possible_Ways (matrix, 25) 2 #2 ways to reach destination Explanation: 2 ways to reach destination #fright.right down, downright] and cost is 1+3+8+6+2+5 = 25 #[down,right,right,down,right] and cost is 1+10+1+6+2+5 = 25 جام Implementation requlrements: 1. Your implementation should be recursive. 2. If you need, you may define and use additional functions. 3. Don't worry about runtime for this question. 4. You have to find all possible ways using exactly totalGasAmount. Summation of the paths gas amounts (including bottom right cell's gas amount) should be equal to totalGasAmount. def find_number_of_A11_Possible_Ways (matrix, totalGasAmount): : Input type matrix: list of lists Input type totalGasAmount: positive integer, total amount of Gas we have Return type: integer HE Please upload your solution (a .py file having python code) here. Please select file(s) Select file(s)
Answers
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks
Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.
#code
# required method def find_Number_Of_All_Possible_Ways(matrix, totalGasAmount): # calling helper method, passing matrix, 0,0 as initial position, and totalGasAmount as gas left return helper(matrix, 0, 0, totalGasAmount) # recursive helper method to assist the above method def helper(matrix, current_row, current_col, gasLeft): # if current_row or current_col went out of range, returning 0 (means no path found) if current_row >= len(matrix) or current_col >= len(matrix[current_row]) or gasLeft < 0: return 0 # otherwise subtracting gas amount of current position from gasLeft gasLeft -= matrix[current_row][current_col] # if this is the last location and gasLeft is 0, we found a path, returning 1 (for current path) if current_row == len(matrix) - 1 and current_col == len(matrix[current_row]) - 1 and gasLeft == 0: return 1 # otherwise making two recursive calls to helper method, one going down (moving to next row) and one going right # (moving to next column), and returning the sum of values returned by both calls return helper(matrix, current_row + 1, current_col, gasLeft) + helper(matrix, current_row, current_col + 1, gasLeft) # end of helper method # code for testing, remove if not needed matrix = [ [1, 3, 8, 7], [10, 1, 6, 20], [23, 30, 2, 5] ] print(find_Number_Of_All_Possible_Ways(matrix, 25)) # 2#output
2
Similar Solved Questions
1 answers
Find the force necessary to start the crate moving, given that the mass of the crate is 32 and...
Find the force necessary to start the crate moving, given that the mass of the crate is 32 and the coefficient of static friction between the crate and the floor is0.57....
1 answers
How do we do this on a calculator? Test the claim that the mean GPA of...
how do we do this on a calculator? Test the claim that the mean GPA of Orange Coast students is smaller than the mean GPA of Coastline students at the 0.10 significance level. The null and alternative hypothesis would be: H:Ho Mc HoHo = Mc Ho: Po > Pc Ho: Po = Pc H:HO MC Ho: Po PC H : Ho < ...
1 answers
Bandar Industries Berhad of Malaysia manufactures sporting equipment. One of the company’s products, a football helmet...
Bandar Industries Berhad of Malaysia manufactures sporting equipment. One of the company’s products, a football helmet for the North American market, requires a special plastic. During the quarter ending June 30, the company manufactured 3,000 helmets, using 1,980 kilograms of plastic. The pla...
1 answers
Unit over the relevant range of 59,000 to 99,000 units is given below 2. Assume that...
unit over the relevant range of 59,000 to 99,000 units is given below 2. Assume that the company produces and sells 89,000 units during the year at a selling price of $8.16 per unit. Prepare a for the year 59,000 360,000 513,400...
1 answers
Assignment #12 Group # Your Name: Negative Externalities Price and lost, & perton IMC 100 MB...
Assignment #12 Group # Your Name: Negative Externalities Price and lost, & perton IMC 100 MB o to 20 20 40 60 70 10 Too Q This figure shows MB and MC related to production and consumption of paper products. MEC of one extra ton of paper is $150 per ton. 1. How many tons of the paper products sho...
1 answers
A researcher collects two independent random samples of sizes n = 22 and n2 = 27,...
A researcher collects two independent random samples of sizes n = 22 and n2 = 27, and computes the means, x, and x2 and the standard deviations, s, and s2, of each sample. She plans to use a t-test to determine if there is a difference between the two population means, Hi and 2. She does not know th...
1 answers
Financial Statements Analysis Online Assignment Question #4 Home center Inc. a furniture whole seller acquired new...
Financial Statements Analysis Online Assignment Question #4 Home center Inc. a furniture whole seller acquired new equipment at a cost of $150,000 at the beginning of the fiscal year. The equipment as an estimated life of five year and an estimated residual value of $12,000. President of Home center...
1 answers
How do write standard form of equation of the parabola given that vertex is (5/2, - 3/4) and graph passes through point (-2 ,4)?
How do write standard form of equation of the parabola given that vertex is (5/2, - 3/4) and graph passes through point (-2 ,4)?...
1 answers
For the curve r(t) find an equation for the indicated plane at the given value of...
for the curve r(t) find an equation for the indicated plane at the given value of t 56) r(t) (t2-6)i+ (2t-3)j+9k; osculating plane at t=6 A) x+ y+(z+9)=0 C)x+y+ (z-9)-0 56) B) z-9 D) z -9 (3t sint+3 cos t)i + (3t cos t-3 sin t)j+ 4k; normal plane at t 1.5r.. A) y=-3 57) r(t) 57) B) y 3 C)x-y+z-3 D) ...
1 answers
[5 points] We learnt in class that the "total heat rate lost from the entire fin...
[5 points] We learnt in class that the "total heat rate lost from the entire fin to the surroundings through convection" ат = 9f --KA where x=0 represents the base of the fin. da at x=0 Consider a similar situation, except that heat is being generated in the fin at a constant rat...
1 answers
5.27X104. Suppose the molecules of a gas at 600. K can exist in two possible energy...
5.27X104. Suppose the molecules of a gas at 600. K can exist in two possible energy states: E = 2.49x100, 2 Calculate the fraction of molecules in each energy state using the Boltzmann distribution equation. fraction in E12 fraction in E...
1 answers
Actate Fermentation Alcoholic Fermentation Description Starts with glycolysis Generates pyruvate at the end of glycolysis Does...
actate Fermentation Alcoholic Fermentation Description Starts with glycolysis Generates pyruvate at the end of glycolysis Does not generate any CO2 Starts with six-carbon glucose and ends with two molecules of a two-carbon by-product 000 Many people enjoy sugary soda pop because it is fizzy. This fi...