Skip to main content
deleted 72 characters in body
Source Link
att
  • 21.7k
  • 2
  • 16
  • 62

Wolfram Language (Mathematica), 4949 32 bytes

PositionIndex@Tuples[0|0|1|1,#]&

Try it online!

Returns an Association where the values correspond with rows of the matrix (associations are ordered). For a traditional list-of-lists output, prepend List@@ (+6 bytes).

Port of Lynn's Jelly solution.


Older solution:

Outer[#+##&,t=#~FromDigits~4&/@{0,1}~Tuples~#,t]&

Try it online!

Fold[3#+##&] would save 3 bytes over #~FromDigits~4, but fails to correctly handle n=0: Try it online!

Wolfram Language (Mathematica), 49 bytes

Outer[#+##&,t=#~FromDigits~4&/@{0,1}~Tuples~#,t]&

Try it online!

Fold[3#+##&] would save 3 bytes over #~FromDigits~4, but fails to correctly handle n=0: Try it online!

Wolfram Language (Mathematica), 49 32 bytes

PositionIndex@Tuples[0|0|1|1,#]&

Try it online!

Returns an Association where the values correspond with rows of the matrix (associations are ordered). For a traditional list-of-lists output, prepend List@@ (+6 bytes).

Port of Lynn's Jelly solution.


Older solution:

Outer[#+##&,t=#~FromDigits~4&/@{0,1}~Tuples~#,t]&

Try it online!

added 309 characters in body
Source Link
att
  • 21.7k
  • 2
  • 16
  • 62

Wolfram Language (Mathematica), 49 bytes

Outer[#+##&,t=#~FromDigits~4&/@{0,1}~Tuples~#,t]&

Try it online!

Fold[3#+##&] would save 3 bytes over #~FromDigits~4, but fails to correctly handle n=0: Try it online!

Wolfram Language (Mathematica), 49 bytes

Outer[#+##&,t=#~FromDigits~4&/@{0,1}~Tuples~#,t]&

Try it online!

Wolfram Language (Mathematica), 49 bytes

Outer[#+##&,t=#~FromDigits~4&/@{0,1}~Tuples~#,t]&

Try it online!

Fold[3#+##&] would save 3 bytes over #~FromDigits~4, but fails to correctly handle n=0: Try it online!

Source Link
att
  • 21.7k
  • 2
  • 16
  • 62

Wolfram Language (Mathematica), 49 bytes

Outer[#+##&,t=#~FromDigits~4&/@{0,1}~Tuples~#,t]&

Try it online!