Anonymous user
Power set: Difference between revisions
→{{header|Perl}}: whitespace is not the enemy
(→{{header|Perl 6}}: supply in the form of a function, as specced) |
(→{{header|Perl}}: whitespace is not the enemy) |
||
Line 1,511:
=={{header|Perl}}==
<lang perl>sub p{@_?map{$_,[$_[0],@$_]}p(@_[1..$#_]):[]}</lang>▼
Using a recursive function:
<lang perl>sub powerset {
}</lang>
Using list folding:
<lang perl>use List::Util qw(reduce);
sub powerset {
@{ (reduce { [@$a, map([@$_, $b], @$a)] } [[]], @_) }
}</lang>
=={{header|Perl 6}}==
<lang perl6>sub powerset(Set $s) { set $s.combinations.map: *.Set }
|