conected cities
conected cities
(OP)
If i have this links:
How can i find witch pair of distinct cities are connected using 2 links ? Any ideea ? Thanks
CODE
link(detroit,toronto).
link(chicago,washington).
link(denver,sacramento).
link(sacramento,chicago).
link(toronto,chicago).
....................
link(chicago,washington).
link(denver,sacramento).
link(sacramento,chicago).
link(toronto,chicago).
....................
How can i find witch pair of distinct cities are connected using 2 links ? Any ideea ? Thanks
RE: conected cities
Also, take care of cycles. You'll see that a naive approach to this problem would report each city as being connected to itself by 2 links, because A - B and B - A also fulfill the rule above.
RE: conected cities
I need one sample of the output that you want
ie,one virtual result of the program.
thanks
RE: conected cities
RE: conected cities
link(detroit,toronto).
link(chicago,washington).
link(denver,sacramento).
link(sacramento,chicago).
link(toronto,chicago).
connected(X,Z):-link(X,Y),link(Y,Z).
%connected(X,Z):-link(Z,Y),link(Y,X).
cities(X,Y,C):-findall([X,Y],connected(X,Y),C).