Skip to main content
added 440 characters in body
Source Link
ngn
  • 15.3k
  • 2
  • 43
  • 87

APL (Dyalog Classic), 13 bytes

⍪,⊃∘.,/⎕,¨⊂⊂⍬

Try it online!

outputOutput:

 1 2 3 
 1 2   
 1 3   
 1     
 2 3   
 2     
 3     
       

there'sThere's a blank line at the end to represent the empty set.

Explanation:

evaluated input

⎕,¨⊂⊂⍬ append an empty numeric list after each element

∘., Cartesian product

/ reduction (foldr)

disclose (necessary after reduction in APL)

At this point the result is an n-dimensional 2-by-...-by-2 array, where n is the length of the input.

, flatten into a vector

turn the vector into an upright 2n-by-1 matrix, so each subset is on a separate line

APL (Dyalog Classic), 13 bytes

⍪,⊃∘.,/⎕,¨⊂⊂⍬

Try it online!

output:

 1 2 3 
 1 2   
 1 3   
 1     
 2 3   
 2     
 3     
       

there's a blank line at the end to represent the empty set

APL (Dyalog Classic), 13 bytes

⍪,⊃∘.,/⎕,¨⊂⊂⍬

Try it online!

Output:

 1 2 3 
 1 2   
 1 3   
 1     
 2 3   
 2     
 3     
       

There's a blank line at the end to represent the empty set.

Explanation:

evaluated input

⎕,¨⊂⊂⍬ append an empty numeric list after each element

∘., Cartesian product

/ reduction (foldr)

disclose (necessary after reduction in APL)

At this point the result is an n-dimensional 2-by-...-by-2 array, where n is the length of the input.

, flatten into a vector

turn the vector into an upright 2n-by-1 matrix, so each subset is on a separate line

Source Link
ngn
  • 15.3k
  • 2
  • 43
  • 87

APL (Dyalog Classic), 13 bytes

⍪,⊃∘.,/⎕,¨⊂⊂⍬

Try it online!

output:

 1 2 3 
 1 2   
 1 3   
 1     
 2 3   
 2     
 3     
       

there's a blank line at the end to represent the empty set