Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 80 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATL, 10 bytes

YsG~YsQ1Z?

Inputs an array of binary digits. Outputs a matrix.

Try it online!

Explanation

Ys % Implicit input: array of binary digits. Cumulative sum. This gives the
 % row coordinates
G % Push input again
~ % Negate: change 0 to 1 and 1 to 0
Ys % Cumulative sum
Q % Add 1. This gives the column coordinates
1Z? % Matrix containing 1 at those row and column coordinates and 0 otherwise.
 % Implicit display

MATL, 10 bytes

YsG~YsQ1Z?

Inputs an array of binary digits. Outputs a matrix.

Try it online!

Explanation

Ys % Implicit input: array of binary digits. Cumulative sum
G % Push input again
~ % Negate: change 0 to 1 and 1 to 0
Ys % Cumulative sum
Q % Add 1
1Z? % Matrix containing 1 at those row and column coordinates and 0 otherwise.
 % Implicit display

MATL, 10 bytes

YsG~YsQ1Z?

Inputs an array of binary digits. Outputs a matrix.

Try it online!

Explanation

Ys % Implicit input: array of binary digits. Cumulative sum. This gives the
 % row coordinates
G % Push input again
~ % Negate: change 0 to 1 and 1 to 0
Ys % Cumulative sum
Q % Add 1. This gives the column coordinates
1Z? % Matrix containing 1 at those row and column coordinates and 0 otherwise.
 % Implicit display
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATL, 10 bytes

YsG~YsQ1Z?

Inputs an array of binary digits. Outputs a matrix.

Try it online!

Explanation

Ys % Implicit input: array of binary digits. Cumulative sum
G % Push input again
~ % Negate: change 0 to 1 and 1 to 0
Ys % Cumulative sum
Q % Add 1
1Z? % Matrix containing 1 at those row and column coordinates and 0 otherwise.
 % Implicit display

AltStyle によって変換されたページ (->オリジナル) /