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")

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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 

Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY