Created
June 12, 2019 20:16
-
-
Save jnpn/d832a60f0df8e89c678f9ee5a38d2ed1 to your computer and use it in GitHub Desktop.
Enumeration recursive de l'Ensemble Puissance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Un peu de combinatoire: | |
;; | |
;; Definition recursive de l'Ensemble Puissance (powerset) | |
;; (avec variantes stylistiques) | |
(setq lexical-binding t) | |
(defun pset (s) | |
(if (null s) | |
'(()) | |
(let* ((subs (pset (cdr s))) | |
(aug (mapcar (lambda (sub) | |
(cons (car s) sub)) | |
subs))) | |
(append aug subs)))) | |
(= (length (pset '(a b c))) 8) | |
(defun pset-cond (s) | |
(cond ((null s) '(())) | |
(t (let* ((subs (pset-cond (cdr s))) | |
(augs (mapcar (lambda (sub) (cons (car s) sub)) subs))) | |
(append augs subs))))) | |
(pset-cond '(a b c)) | |
(= (length (pset-cond '(a b c))) 8) | |
(defun pset-partial (s) | |
(cond ((null s) '(())) | |
(t (let* ((subs (pset-partial (cdr s))) | |
(pref (-partial #'cons (car s))) | |
(augm (mapcar pref subs))) | |
(append augm subs))))) | |
(pset. '(a b c)) | |
(defun pset-flat (s) | |
(cond ((null s) '(())) | |
(t (let ((pref (-partial #'cons (car s)))) | |
(append (mapcar pref subs) (pset-flat (cdr s))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment