Power set: Difference between revisions
→Non-Mutating Solution
Line 2,221:
===Non-Mutating Solution===
<syntaxhighlight lang="julia">
using Base.Iterators
function powerset(x::Vector{T})::Vector{Vector{T}} where T▼
bit_strings = range(start = 1, stop = 2^length(x)-1) .|>▼
▲function powerset(x::Vector{T})::Vector{Vector{T}} where T
bitstring .|>▼
bitstring_map(x) = Iterators.map(bitstring, x)
reverse▼
reverse_map(x) = Iterators.map(reverse, x)
[[a for (a, b) in zip(x, bits) if b == '1'] for bits in bit_strings]
end
|