<?xml version="1.0"?>
<paste-with-annotations>
  <paste>
    <number>
      <integer>52132</integer>
    </number>
    <user>
      <string>faxathisia</string>
    </user>
    <title>
      <string>graph cycles</string>
    </title>
    <contents>
      <string>(defun contains-duplicates-p (list)
  (/= (length list)
      (length (remove-duplicates list))))

(defparameter *graph* '((a d e)
                        (b b c e f)
                        (c)
                        (d c f)
                        (e a)
                        (f b)))

(defun next-paths (path)
  (mapcar #'(lambda (node) (append path (list node)))
          (cdr (assoc (car (last path)) *graph*))))

(defun next-paths-for-paths (paths)
  (mapcan #'next-paths paths))

(defun cyclep (path)
  (some #'(lambda (path) (equal (first path) (car (last path))))
        (next-paths path)))

(defun all-cycles ()
  (loop for cycles := nil then (append cycles (remove-if-not #'cyclep paths))
        for paths := (mapcar #'list (mapcar #'first *graph*))
        then (remove-if #'contains-duplicates-p (next-paths-for-paths paths))
        while paths
        finally (return cycles)))


</string>
    </contents>
    <universal-time>
      <integer>3406102001</integer>
    </universal-time>
    <channel>
      <string>#lispcafe</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <null/>
    </is-unicode>
  </paste>
</paste-with-annotations>