Question: Course: Artificial Intelligence QUESTION: In the following program given code of [ python programming language ] below. Add and use Artificial Intelligence Algorithm to solve

Course: Artificial Intelligence

QUESTION:

In the following program given code of [ python programming language ] below. Add and use Artificial Intelligence Algorithm to solve the program. And also attach of the output screen.

vis = [] # function will return 1 if can jump to last # else 0 def fun(arr, n, i): # base condition # if reached the last index # return 1 if i == n - 1: return 1 # if i is out of bounds return 0 if i > n or i < 0: return 0 # if we have already visited return 0 if vis[i] == 1: return 0 # make this index as visited one. vis[i] = 1 # check for left and right jump # if any of the jump leads to the last index # return 1 if fun(arr, n, i + arr[i]) or fun(arr, n, i - arr[i]): return 1 # else 0 return 0 # example array arr = [] # number of elements as input n = int(input("Enter number of elements : ")) # iterating till the range for i in range(0, n): ele = int(input()) arr.append(ele) #arr = [4, 4, 1, 5, 2, 6, 3, 4, 2, 0] # make visited array vis = [0] * len(arr) if fun(arr, len(arr), 0): print("Solvable") else: print("Non-Solvable")

Note: solve as soon as possible

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!