Power set: Difference between revisions

Content added Content deleted
(→‎{{header|TXR}}: Condense into one section.)
(→‎{{header|TXR}}: comb version preserves type of input sequence.)
Line 2,854: Line 2,854:
((nil) nil)
((nil) nil)
((1 2 3) (1 2) (1 3) (1) (2 3) (2) (3) nil)</pre>
((1 2 3) (1 2) (1 3) (1) (2 3) (2) (3) nil)</pre>

Here is where the <code>comb</code> version differs in semantics, producing the combinations as sequences of the same type as the input sequence, rather than as lists:

<lang txr>@(do (defun power-set (s)
(mappend* (op comb s) (range 0 (length s))))
(prinl (power-set "abc"))
(prinl (power-set "b"))
(prinl (power-set ""))
(prinl (power-set #(1 2 3))))</lang>

<pre>("" "a" "b" "c" "ab" "ac" "bc" "abc")
("" "b")
("")
(#() #(1) #(2) #(3) #(1 2) #(1 3) #(2 3) #(1 2 3))</pre>


=={{header|UnixPipes}}==
=={{header|UnixPipes}}==