Write a Prolog program with the following knowledge base: directTrain(union-stat
ID: 3798470 • Letter: W
Question
Write a Prolog program with the following knowledge base:
directTrain(union-station, san-bernardino).
directTrain(oxnard, union-station).
directTrain(burbank, lancaster).
directTrain(lancaster, union-station).
directTrain(san-bernardino, riverside).
directTrain(santa-ana, burbank).
directTrain(oceanside, santa-ana).
This knowledge base holds facts about towns you can travel between by taking a direct train, e.g., from union station to san bernardino.
Extend your Prolog program with a rule that adds a directTrain between A and B whenever there is one from B to A.
Explanation / Answer
directTrain(union-station, san-bernardino).
directTrain(oxnard, union-station).
directTrain(burbank, lancaster).
directTrain(lancaster, union-station).
directTrain(san-bernardino, riverside).
directTrain(santa-ana, burbank).
directTrain(oceanside, santa-ana).
directTrainrev(a,b):- directTrain(b,a) // directTrainrev is a rule that adds a directTrain between a and b whenever ther is one from b to a.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.