X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/9a3cb4610ab59001fd44c13dcdc6ea206acf0e50..00d59354c311fb28730b7c9b117b0d91aac092cc:/src/utilities.lisp diff --git a/src/utilities.lisp b/src/utilities.lisp index 1670f55..25733e8 100644 --- a/src/utilities.lisp +++ b/src/utilities.lisp @@ -451,6 +451,25 @@ and return the result of appending all of the resulting lists." (reduce #'append (apply #'mapcar function list more-lists) :from-end t)) +(export 'cross-product) +(defun cross-product (&rest pieces) + "Return the cross product of the PIECES. + + Each arguments may be a list, or a (non-nil) atom, which is equivalent to + a singleton list containing just that atom. Return a list of all possible + lists which can be constructed by taking one item from each argument list + in turn, in an arbitrary order." + (reduce (lambda (piece tails) + (mapcan (lambda (tail) + (mapcar (lambda (head) + (cons head tail)) + (if (listp piece) piece + (list piece)))) + tails)) + pieces + :from-end t + :initial-value '(nil))) + (export 'distinguished-point-shortest-paths) (defun distinguished-point-shortest-paths (root neighbours-func) "Moderately efficient shortest-paths-from-root computation.