Power set: Difference between revisions
Content added Content deleted
(→{{header|Perl}}: whitespace is not the enemy) |
(→{{header|Perl 6}}: simplify, supply alternative impl) |
||
Line 1,526:
=={{header|Perl 6}}==
<lang perl6>sub powerset(Set $s) {
say powerset set <a b c d>;</lang>
{{out}}
<pre>set(set(), set(a), set(b), set(c), set(d), set(a, b), set(a, c), set(a, d), set(b, c), set(b, d), set(c, d), set(a, b, c), set(a, b, d), set(a, c, d), set(b, c, d), set(a, b, c, d))</pre>
If you don't care about the actual <tt>Set</tt> type, the <tt>.combinations</tt> method by itself may be good enough for you:
<lang perl6>.say for <a b c d>.combinations</lang>
{{out}}
<pre>
a
b
c
d
a b
a c
a d
b c
b d
c d
a b c
a b d
a c d
b c d
a b c d</pre>
=={{header|PHP}}==
|