Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun combos (list)
- (let* ((a (car list))
- (d (cdr list))
- (s (and d (combos d)))
- (v (loop for c in s collect (cons a c))))
- (cons (list a) (append s v))))
- ;; Requires SRFI 26
- (define (combos lst)
- (if (null? lst) '(())
- (let* ((a (car lst))
- (d (cdr lst))
- (s (combos d))
- (v (map (cut cons a <>) s)))
- (append s v))))
- (defun combos (list)
- (if (null list) '(nil)
- (let* ((a (car list))
- (d (cdr list))
- (s (combos d))
- (v (mapcar (lambda (x) (cons a x)) s)))
- (append s v))))
- (defun subsets (list)
- "Return a list of the subsets of LIST."
- (if (null list) '(nil)
- (let ((e (car list))
- (ss (subsets (cdr list))))
- (append ss (loop for s in ss collect (cons e s))))))
- (defun non-empty-subsets (list)
- "Return a list of the non-empty subsets of LIST."
- (cdr (subsets list)))
Add Comment
Please, Sign In to add comment