Prolog Homework #3
This is expected to be entirely worked through during class. It is okay to just submit your classwork to this assignment.
1) Find the edges
Connected points
edge(a, b).
edge(b, c).
edge(b, d).
edge(b, e).
edge(d, e).
edge(y,x).
edge(x,z).
What points can you reach from a particular point? Assume no circular connections.
These queries should work as follows:
connected(a,X).
X = b ;
X = c ;
X = d ;
X = e ;
false.
connected(X,z).
X = x ;
X = y ;
false.
2) Walk the edges
Show the path that connects from one edge to another
connectedPath(a,e,X).
Should give:
X = go(a, b, go(b, e)) ;
X = go(a, b, go(b, d, go(d, e))) ;
3) Count the number of possible steps between two points.
countConnections(a,e,0,X).
X = 2 ;
X = 3 ;
3) Translate a list of starting points of each edge, to ending points of each edge
Sample run with the same edges as in #1
endPath([a,b,x],X).
X = [b, c, z] ;
X = [b, d, z] ;
X = [b, e, z].
endPath([a,b,d],X).
X = [b, c, e] ;
X = [b, d, e] ;
X = [b, e, e].
4) Build a list of the edges you travel
connectedPathtoList(a,e, a,X).
X = [[a, edge(a, b)]|edge(b, e)] ;
X = [[[a, edge(a, b)], edge(b, d)]|edge(d, e)] .