Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Challenging prolog question for smart people

Status
Not open for further replies.

franklintaniredjo

Programmer
Feb 1, 2004
2
CA
Imagine a robot that can travel between rooms in an office-type environment. Before the robot can move from its current location to a destination, it has to find what sequence of rooms leads to the destination. Assume that each room is next to at least one other room, the robot can go between neighboring rooms in both directions and the average time of traveling between neighboring rooms is given in advance. Let adjacent(List) be the predicate that holds if List contains all lists [Room1,Room2,Time] such that the Room1 is next to Room2; in other words, there is a passage from Room1 to Room2 and it takes the robot Time to go from one of them to another. For Example,

adjacent([ [r1,r2,4],[r1,r3,6],[r2,r4,3],[r4,r5,1],[r3,r6,8],[r1,r5,5] ]).

means that the robot can go directly from r1 to r2 or from r2 to r1 spending 4 units of time on this move, etc. Note that each pair of rooms is mentioned in the list above only once, but the robot can go in any direction between rooms that are next to each other. Let trip(Start,End,Path,Total) be the predicate that is true if Start is the room where the robot is currently located, End is the destination room, Path is a list of rooms that the robot will pass on its way and Total is the total time that the robot spends traveling. (The list Path includes also the rooms Start, End.) Write a recursive program that implements the predicate trip(Start,End,Path,Total). Your program must compute a list Path such that each element occurs in this list only once: the robot never moves through the same room more than once when it travels from Start to End.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top