Zsh, 6631 bytes
for ((;2**$#>i++;)){j=;for s
((i&1<<j++))&&echo ${(P)j}' \c'
echo}
Pretty standard nested for loop comparison, similar the C and js answersAccidentally cut my previous byte-count in half answering another prompt. Try it online!..
Zsh, 71 bytes
for s;a=($^@'
'$^a)
for s ($a);b+=i;a=(${(j: :)${(uof)s}$i,}\ $^a)
<<<${(F)${(u)b}a}
Progressively builds up the cartesian product S^N, then eliminates repeated coordinates in a single element: (0 0 1 0
-> 0 1
), then eliminates repeated elements: (0 1
, 0 1
-> 0 1
).Try it online!
Here's an expanded versionDelimiter is one or more spaces, with some examples:
for s in $@; do # 'for s in {a,b,c}' ensures we iterate 3 times
cprod=( ${^@}$'\n'${^cprod} ) # ex: {a,b,c}{aa,ab,ac,ba,bb,bc,ca,cb,cc}
done # (actually, $'a\na\na' $'a\na\nb' ...)
for xyz in $cprod; do # ex: xyz=$'a\nb\na'
unique_elems=${(uof)xyz} # $'a\nb\na' -(f)-> a b a -(o)-> a a b -(u)> a b
sets+=( ${(j: :)unique_elems} # a b -(j: :)> 'a b'
done
unique_sets=(${(u)sets}) # a 'a b' 'a b' b -(u)> a 'a b' b
<<< ${(F)unique_sets} # a 'a b' b -(F)> $'a\na b\nb'
Try it online!we abuse trailing delimiters extensively here.