Guest User

Untitled

a guest
Jul 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. (defun combos (list)
  2. (let* ((a (car list))
  3. (d (cdr list))
  4. (s (and d (combos d)))
  5. (v (loop for c in s collect (cons a c))))
  6. (cons (list a) (append s v))))
  7.  
  8. ;; Requires SRFI 26
  9. (define (combos lst)
  10. (if (null? lst) '(())
  11. (let* ((a (car lst))
  12. (d (cdr lst))
  13. (s (combos d))
  14. (v (map (cut cons a <>) s)))
  15. (append s v))))
  16.  
  17. (defun combos (list)
  18. (if (null list) '(nil)
  19. (let* ((a (car list))
  20. (d (cdr list))
  21. (s (combos d))
  22. (v (mapcar (lambda (x) (cons a x)) s)))
  23. (append s v))))
  24.  
  25. (defun subsets (list)
  26. "Return a list of the subsets of LIST."
  27. (if (null list) '(nil)
  28. (let ((e (car list))
  29. (ss (subsets (cdr list))))
  30. (append ss (loop for s in ss collect (cons e s))))))
  31.  
  32. (defun non-empty-subsets (list)
  33. "Return a list of the non-empty subsets of LIST."
  34. (cdr (subsets list)))
Add Comment
Please, Sign In to add comment