Paste number 52642: cartesian-product

Index of paste annotations: 1

Paste number 52642: cartesian-product
Pasted by: faxathisia
When:4 years, 1 month ago
Share:Tweet this! | http://paste.lisp.org/+14MA
Channel:#lispcafe
Paste contents:
Raw Source | XML | Display As
(defun cartesian-product (&rest lists)
  (if (endp lists) '(())
      (apply #'append
             (mapcar #'(lambda (head) (mapcar #'(lambda (tail) (cons head tail))
                                              (apply #'cartesian-product (rest lists))))
                     (first lists)))))

Annotations for this paste:

Annotation number 1: cartesian-product car/cdr
Pasted by: faxathisia
When:4 years, 1 month ago
Share:Tweet this! | http://paste.lisp.org/+14MA/1
Paste contents:
Raw Source | Display As
(defun cartesian-product (list &rest lists)
  (if (endp lists) (mapcar #'list list)
      (apply #'append
             (mapcar #'(lambda (head) (mapcar #'(lambda (tail) (cons head tail))
                                              (apply #'cartesian-product lists)))
                     list))))

Colorize as:
Show Line Numbers
Index of paste annotations: 1

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.