Question

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 a

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 d

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
PYTHON Im stuck on this problem, PLEASE HELP! and please follow the implementation requirements! THANK YOU!...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PYTHON this implementation is really hard, Im stuck especially with the requirements they give. PLEASE HELP!...

    PYTHON this implementation is really hard, Im stuck especially with the requirements they give. PLEASE HELP! THANK YOU! RECURSIVE! Give a recursive python implementation of the following function: def check_Decreasing_Order(lissy): Given lissy, a python list of integers, the above function will return True if lissy is sorted in decreasing order, otherwise it will return false. For example, print(check_Decreasing Order([100,50,8, -2])) True print(check_Decreasing_Order([108,50,8,2,35])) False Implementation Requirements: 1. Your implementation must be recursive. 2. If you need more parameters, you may define...

  • PYTHON please help! im stuck on this homework question, THANK YOU! please follow the rules! Give...

    PYTHON please help! im stuck on this homework question, THANK YOU! please follow the rules! Give a recursive python implementation of the following function: def check_Decreasing_Order(lissy): Given lissy, a python list of integers, the above function will return True if lissy is sorted in decreasing order, otherwise it will return false. For example, print(check_Decreasing Order([100,50,8, -2])) True print(check_Decreasing_Order([108,50,8,2,35])) False Implementation Requirements: 1. Your implementation must be recursive. 2. If you need more parameters, you may define new functions or helper...

  • PYTHON Stuck with this problem with these implementation requirements. PLEASE HELP! THANK YOU! PYTHON Q7 16...

    PYTHON Stuck with this problem with these implementation requirements. PLEASE HELP! THANK YOU! PYTHON Q7 16 Points Give a python implementation of the following function: def without_Vowels(listi): The above function gets a list of positive integers and English letters, list1. When called, it should remove all the vowels from list1, and keep only the consonants and integers. The Order of the remaining consonants and integers does not matter. For example, if list1 = ['a', 'b', 5, 'c', 'o', 2, 'e',...

  • PYTHON I need help with this Python problem, please follow all the rules! Please help! THANK...

    PYTHON I need help with this Python problem, please follow all the rules! Please help! THANK YOU! Bonus Question Implement an efficient algorithm (Python code) for finding the 11th largest element in a list of size n. Assume that n will be greater than 11. det find 11th largest numberlissy Given, lissy, a list of n integers, the above function will return the 11th largest integer from lissy You can assume that length of lissy will be greater than 11....

  • PYTHON Im stuck, this is one line of code but I just cant remember it... Please...

    PYTHON Im stuck, this is one line of code but I just cant remember it... Please Help! Thank YOU! LIST COMPREHENSION Create a python list, that stores exactly [0,'hi', 2, thi', 4, thi', 6, 'hi', 8, thi') using python list comprehension. You can write one line of python code directly below (in the text box) or you can upload a python file having only one line of code. Write your solution (one line of python code) here. Enter your answer...

  • Please help with this python assignment. Thank you. question 1 Write a Python program to read...

    Please help with this python assignment. Thank you. question 1 Write a Python program to read a file line by line store it into a variable. question 2 Write a Python program to read a file line by line store it into an array. question 3 Write a python program to find the longest words. question 4 Write a Python program to count the number of lines in a text file. question 5 Write a Python program to count the...

  • PYTHON: Im stuck here, big O notation and runtime. What is it and Why are they...

    PYTHON: Im stuck here, big O notation and runtime. What is it and Why are they those? Please look at the pic, need help as Im confused. Thank You! def method3(n): for i in range(n): for j in range(100): for k in range(n): print(i+j+k) What is the runtime (tightest/closest bound in terms of O) for the above python function (method 3)? Please briefly explain. Enter your answer here def method4(n): for i in range(n): for j in range(n, o, -2):...

  • PLease help!!! how to type them in Python !!!! Python help!! THank you so much Problem...

    PLease help!!! how to type them in Python !!!! Python help!! THank you so much Problem 1: (20 points) Optimal change You will write a program that uses the // and % operators to figure out how to give change for a specified amount using the minimum number of coins (quarters, dimes, nickels, cents). The good news is that our currency is specifically designed to make this problem easy. For a given number of cents, first use as many quarters...

  • This is my assignment in Python. Please help me thank you Design type 1: # Creating an object of ...

    This is my assignment in Python. Please help me thank you Design type 1: # Creating an object of the class "Burger" theOrder = Burger() # calling the main method theOrder.main() # And the class is like: class Burger: # You may need to have a constructor def __init__(self): self._orderDict = {} self._priceBeforeTax = 0 self._priceAfterTax = 0 # you may have the tax rate also as an instance variable. But as I mentioned, you can use your # own...

  • PYTHON please help, stuck on this output and memory image! THANK YOU! Q3 7 Points import...

    PYTHON please help, stuck on this output and memory image! THANK YOU! Q3 7 Points import copy list1 = [11, [22, 33], [44, 55], 66] list2 = list1 list3 = listi[:] list4 = copy.deepcopy(listi) list1[0] = 100 list1[1][1] = 300 list1 += [77] list2 = list2 + [88] print(listi) print(list2) print(list) print(list) Please write output of the above program below (in the text box) and upload a picture of memory image? Enter your answer here Memory Image: Please select file(s)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT