# [Zsh], 66 bytes <!-- language-all: lang-sh --> 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 answers. [Try it online!][TIO-jzqchlws] [Zsh]: https://www.zsh.org/ [TIO-jzqchlws]: https://tio.run/##NYxNCoMwGET33ykGGkxiENS6S@wZeoBuRFNMEAPaH6h49tRQOjAz8Bbvs47xPbrJYrHdgMnNVmMIZF/dhNU@UBRgicZ7WCCErvOcnS5OKS3l5lud8EpCuKwyxislZZbZfgxgm7hKv3Pcek6J7NEYA94e4fSck9zBg4Zw2KmkElUq6t/i/H809AU "Zsh – Try It Online" ---- # [Zsh], 71 bytes <!-- language-all: lang-sh --> for s;a=($^@' '$^a) for s ($a);b+=(${(j: :)${(uof)s}}) <<<${(F)${(u)b}} 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`). Here's an expanded version, 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!][TIO-jzqex0lc] [Zsh]: https://www.zsh.org/ [TIO-jzqex0lc]: https://tio.run/##JY3LCoMwEEX38xV3EYihCPax0ghd9TOEsYloEQOmttCSb08TO3AZzhmY@/FjfI/TbLFaNpinxTYwjuyLZ3j7RFlCZBsHt8I33Baiu0qSomNFu0MhWDX9IV2@xaNGrdLe3KB8CIq01glvu1N9CDEJyDaNpG3JDUzGpf9UUYVjDk7E6HGH@RPOuNAP "Zsh – Try It Online"