Skip to main content
deleted 1368 characters in body
Source Link
GammaFunction
  • 6.9k
  • 13
  • 23

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.

Zsh, 66 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 answers. Try it online!


Zsh, 71 bytes

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!

Zsh, 31 bytes

Accidentally cut my previous byte-count in half answering another prompt...

for i;a=({$i,}\ $^a)
<<<${(F)a}

Try it online!

Delimiter is one or more spaces, we abuse trailing delimiters extensively here.

added 2 characters in body
Source Link
GammaFunction
  • 6.9k
  • 13
  • 23

Zsh, 66 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 answers. Try it online!


Zsh, 71 bytes

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!Try it online!

Zsh, 66 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 answers. Try it online!


Zsh, 71 bytes

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!

Zsh, 66 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 answers. Try it online!


Zsh, 71 bytes

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!

Source Link
GammaFunction
  • 6.9k
  • 13
  • 23

Zsh, 66 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 answers. Try it online!


Zsh, 71 bytes

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!