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 39 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATL, 7 bytes

X>tG=s*

Input is a two-row matrix, where each row is one of the arrays.

Try it online!

Explanation

X> % Implicit input. Maximum of each column
t % Duplicate
G % Push input
= % Is equal? Element-wise with broascastbroadcast. Gives a two-row matrix
s % Sum of each column. Gives a row vector containing 1 and 2
* % Multiply, element-wise. Implicit display

MATL, 7 bytes

X>tG=s*

Input is a two-row matrix, where each row is one of the arrays.

Try it online!

Explanation

X> % Implicit input. Maximum of each column
t % Duplicate
G % Push input
= % Is equal? Element-wise with broascast
s % Sum. Gives a row vector containing 1 and 2
* % Multiply, element-wise. Implicit display

MATL, 7 bytes

X>tG=s*

Input is a two-row matrix, where each row is one of the arrays.

Try it online!

Explanation

X> % Implicit input. Maximum of each column
t % Duplicate
G % Push input
= % Is equal? Element-wise with broadcast. Gives a two-row matrix
s % Sum of each column. Gives a row vector containing 1 and 2
* % Multiply, element-wise. Implicit display
edited body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATL, 7 bytes

X>tG=s*

Input is a two-row matrix, where each row is one of the arrays.

Try it online!

Explanation

X> % Implicit input. Maximum of each column
t % Duplicate
G % Push input
= % Is equal? Element-wise with broascast
s % Sum. Gives a row vector containing 1 and 2
* $% Multiply, element-wise. Implicit display

MATL, 7 bytes

X>tG=s*

Input is a two-row matrix, where each row is one of the arrays.

Try it online!

Explanation

X> % Implicit input. Maximum of each column
t % Duplicate
G % Push input
= % Is equal? Element-wise with broascast
s % Sum. Gives a row vector containing 1 and 2
* $ Multiply, element-wise. Implicit display

MATL, 7 bytes

X>tG=s*

Input is a two-row matrix, where each row is one of the arrays.

Try it online!

Explanation

X> % Implicit input. Maximum of each column
t % Duplicate
G % Push input
= % Is equal? Element-wise with broascast
s % Sum. Gives a row vector containing 1 and 2
* % Multiply, element-wise. Implicit display
added 261 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATL, 7 bytes

X>tG=s*

Input is a two-row matrix, where each row is one of the arrays.

Try it online!

Explanation

X> % Implicit input. Maximum of each column
t % Duplicate
G % Push input
= % Is equal? Element-wise with broascast
s % Sum. Gives a row vector containing 1 and 2
* $ Multiply, element-wise. Implicit display

MATL, 7 bytes

X>tG=s*

Input is a two-row matrix, where each row is one of the arrays.

Try it online!

MATL, 7 bytes

X>tG=s*

Input is a two-row matrix, where each row is one of the arrays.

Try it online!

Explanation

X> % Implicit input. Maximum of each column
t % Duplicate
G % Push input
= % Is equal? Element-wise with broascast
s % Sum. Gives a row vector containing 1 and 2
* $ Multiply, element-wise. Implicit display
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading

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