(defconstant +graph1+ '((a (b c)) (b (d)) (c (b d)) (d (c e)) (e (f)) (f (g))) "A directed graph, represented as an association list between nodes (A-F) and, for each node, a set of the states you can get to from that node." ) (defun next-nodes (node graph) "Returns a set of the nodes you can get to in the graph directly from the given node, i.e. in one step. " ;; Fill in the body of this function ) (defun next-nodes-set (nodeset graph) "Nodeset is a set of nodes. This function returns a set of the nodes you can get to in the graph directly (i.e. in one step) from any node in nodeset. " ;; Fill in the body of this function ) (defun exactly-reachable-nodes (source graph numsteps) "Returns the nodes in graph that you can get to from source in exactly numsteps steps. " ;; This one's free: don't change it! ;; Yes, I know I'm using setf. But at least I'm only ;; using it to side-effect a local variable, not a global. ;; There are ways to write this function without using ;; setf at all, but I'm being lazy. So sue me... :-) ;; (let ((nodeset (list source))) (dotimes (i numsteps) (setf nodeset (next-nodes-set nodeset graph))) nodeset)) (defun exactly-reachablep (source target graph maxsteps) "Returns t if you can get from source to target in graph in exactly maxsteps steps, nil otherwise. " ;; Fill in the body of this function )