Question: n Prolog, you are going to write a maze solver. You will write the rule: solve ( X , Y ) where X is the

n Prolog, you are going to write a maze solver. You will write the rule:
solve(X, Y)
where X is the starting point and Y is the ending point. It will determine if there is a
path between those points using facts in the form of:
path(a,b).
Where a is the starting point of the path and b is the ending point. Paths in this
question are directional. This means that path(a,b) means there is a path from a to
b but not b to a.
Example Facts:
path(a,b).
path(b,c).
path(c,d).
path(e,f).
Example queries:
solve(a,b): would result in true. There is a direct path.
solve(b,a): would be false.
solve(a,d): would be true. Path is a-b-c-d.
solve(a,f): would be false.
Your solution should work for any length path.
2. Now modify your solution to allow paths to be bi-directional. So path(a,b), allow
travel from a to b and b to a.
3. Now modify your solution to add distance of the path.The for of solve will be:
solve(X, Y, D)
Where D is now the number of paths it took.
For example using the facts above, solve(a,b,D would say D is 1. solve(a,d,D)
would be 3.
1
4. Now modify that solution to allow for paths to have different lengths. Path would not
be in the form:
path(a,b,10).
Where 10 is the distance of that path.
Example Facts:
path(a,b.20).
path(b,c,10).
path(c,d,100).
path(e,f,5).
Example queries:
solve(a,b,D): would result in true and D of 20
solve(b,a,D): would result in true and D of 20
solve(a,d,D): would be true and a D of 130.
solve(a,f,D): would be false.
5. Does your solution handle infinite circular paths? For instance with bidirectional paths,
you can have a path from a to c of (a,b,c) and (a,b,a,b,c) and (a,b,a,b,a,b,c). Explain
how you would handle this. You do not need to write the code for it.

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!