Jump to content

Power set: Difference between revisions

(→‎{{header|Go}}: Improved set type. Could be considered a bug fix. Set equality code was requiring sets to be in the same order. New code follows conventional meaning of set as an unordered collection.)
(→‎{{header|Common Lisp}}: add an example)
Line 556:
>(powerset '(1 2 3)
(NIL (1) (2) (1 2) (3) (1 3) (2 3) (1 2 3))
 
Yet another imperative solution, this time with dolist.
<lang lisp>(defun power-set (list)
(let ((pow-set (list nil)))
(dolist (element (reverse list) pow-set)
(dolist (set pow-set)
(push (cons element set) pow-set)))))</lang>
Output:
>(power-set '(1 2 3))
((1) (1 3) (1 2 3) (1 2) (2) (2 3) (3) NIL)
 
=={{header|D}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.