Advertisement
KillianMills

routes.pl

Oct 22nd, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.87 KB | None | 0 0
  1. /* Facts */
  2. road(varrock, falador, 5).
  3.  
  4. road(lumbridge, varrock, 4). /* Cycle */
  5. road(varrock, lumbridge, 4).
  6.  
  7. road(lumbridge, draynor, 2).
  8. road(draynor, falador, 3).
  9. road(falador, taverly, 2).
  10. road(falador, portsarim, 3).
  11. road(falador, rimmington, 2).
  12. road(draynor, portsarim, 1).
  13. road(portsarim, rimmington, 1).
  14. road(taverly, catherby, 4).
  15. road(catherby, camelot, 2).
  16. road(camelot, ardougne, 4).
  17. road(camelot, rellekka, 7).
  18. road(varrock, wilderness, 10).
  19.  
  20.  
  21. /* Rules */
  22.  
  23. /* Question1  is true if a route R of length N exists between town X and town Y */
  24. route(X, Y, R, N) :- road(X, Y, N), R1 = [Y], R = [X|R1].
  25. route(X, Y, R, N) :- road(X, Z, N1), route(Z, Y, R1, N2), \+ member(X, R1), R = [X | R1], N is N1+N2.
  26.  
  27.  
  28. /* Question2  is true if the route R of length N between town X and town Y is the shortest route between X and Y */
  29. /* shortest(X,Y,R,N):- .*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement