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, (削除) 9 (削除ここまで) 7 bytes

Thanks to @alephalpha for a correction (the transpose was originally missing).

t!Y*XR~

Inputs a matrix. Outputs a a matrix of ones (which is truthy) if the input is a Hadamard matrix, or a matrix containing at least a zero (which is falsy) otherwise.

Try it online! Or verify all test cases.

How it works

t % Implicit input: matrix M, of size n, with 1 or −1 entries. Duplicate
! % Transpose
Y* % Matrix product. This is a scalar matrix if and only if M is Hadamard
XR % Set entries on the diagonal and below to 0
~ % Negate each entry. Implicit display

MATL, (削除) 9 (削除ここまで) 7 bytes

Thanks to @alephalpha for a correction.

t!Y*XR~

Inputs a matrix. Outputs a a matrix of ones (which is truthy) if the input is a Hadamard matrix, or a matrix containing at least a zero (which is falsy) otherwise.

Try it online! Or verify all test cases.

How it works

t % Implicit input: matrix M, of size n, with 1 or −1 entries. Duplicate
! % Transpose
Y* % Matrix product. This is a scalar matrix if and only if M is Hadamard
XR % Set entries on the diagonal and below to 0
~ % Negate each entry. Implicit display

MATL, (削除) 9 (削除ここまで) 7 bytes

Thanks to @alephalpha for a correction (the transpose was originally missing).

t!Y*XR~

Inputs a matrix. Outputs a a matrix of ones (which is truthy) if the input is a Hadamard matrix, or a matrix containing at least a zero (which is falsy) otherwise.

Try it online! Or verify all test cases.

How it works

t % Implicit input: matrix M, of size n, with 1 or −1 entries. Duplicate
! % Transpose
Y* % Matrix product. This is a scalar matrix if and only if M is Hadamard
XR % Set entries on the diagonal and below to 0
~ % Negate each entry. Implicit display
added 1 character in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATL, (削除) 9 (削除ここまで) 7 bytes

Thanks to @alephalpha for a correction.

t!Y*XR~

Inputs a matrix. Outputs a a matrix of ones (which is truthy) if the input is a HadamrdHadamard matrix, or a matrix containing at least a zero (which is falsy) otherwise.

Try it online! Or verify all test cases.

How it works

t % Implicit input: matrix M, of size n, with 1 or −1 entries. Duplicate
! % Transpose
Y* % Matrix product. This is a scalar matrix if and only if M is Hadamard
XR % Set entries on the diagonal and below to 0
~ % Negate each entry. Implicit display

MATL, (削除) 9 (削除ここまで) 7 bytes

Thanks to @alephalpha for a correction.

t!Y*XR~

Inputs a matrix. Outputs a a matrix of ones (which is truthy) if the input is a Hadamrd matrix, or a matrix containing at least a zero (which is falsy) otherwise.

Try it online! Or verify all test cases.

How it works

t % Implicit input: matrix M, of size n, with 1 or −1 entries. Duplicate
! % Transpose
Y* % Matrix product. This is a scalar matrix if and only if M is Hadamard
XR % Set entries on the diagonal and below to 0
~ % Negate each entry. Implicit display

MATL, (削除) 9 (削除ここまで) 7 bytes

Thanks to @alephalpha for a correction.

t!Y*XR~

Inputs a matrix. Outputs a a matrix of ones (which is truthy) if the input is a Hadamard matrix, or a matrix containing at least a zero (which is falsy) otherwise.

Try it online! Or verify all test cases.

How it works

t % Implicit input: matrix M, of size n, with 1 or −1 entries. Duplicate
! % Transpose
Y* % Matrix product. This is a scalar matrix if and only if M is Hadamard
XR % Set entries on the diagonal and below to 0
~ % Negate each entry. Implicit display
added 164 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATL, 9(削除) 9 (削除ここまで) 7 bytes

Thanks to @alephalpha for a correction.

t!Y*zUGn=Y*XR~

Inputs a matrix. GivesOutputs a a matrix of ones 1 or(which is 0 for Hadamard or non-Hadamardtruthy ) if the input is a Hadamrd matrix, respectivelyor a matrix containing at least a zero (which is falsy ) otherwise.

Try it online! Try it online! Or verify all test cases verify all test cases .

How it works

t % Implicit input: matrix M, of size n, with 1 or −1 entries. Duplicate
! % Transpose
Y* % Matrix product. This is a scalar matrix if and only if M is Hadamard
zXR % Number ofSet non-zeros.entries Giveson nthe ifdiagonal and only if M is Hadamard
U  %below Squareto 0
G % Push input~ again
n % NumberNegate ofeach entriesentry. Gives n^2
= % Equal? Implicit display

MATL, 9 bytes

Thanks to @alephalpha for a correction.

t!Y*zUGn=

Inputs a matrix. Gives 1 or 0 for Hadamard or non-Hadamard, respectively.

Try it online! Or verify all test cases

How it works

t % Implicit input: matrix M, of size n, with 1 or −1 entries. Duplicate
! % Transpose
Y* % Matrix product. This is a scalar matrix if and only if M is Hadamard
z % Number of non-zeros. Gives n if and only if M is Hadamard
U  % Square 
G % Push input again
n % Number of entries. Gives n^2
= % Equal? Implicit display

MATL, (削除) 9 (削除ここまで) 7 bytes

Thanks to @alephalpha for a correction.

t!Y*XR~

Inputs a matrix. Outputs a a matrix of ones (which is truthy ) if the input is a Hadamrd matrix, or a matrix containing at least a zero (which is falsy ) otherwise.

Try it online! Or verify all test cases .

How it works

t % Implicit input: matrix M, of size n, with 1 or −1 entries. Duplicate
! % Transpose
Y* % Matrix product. This is a scalar matrix if and only if M is Hadamard
XR % Set entries on the diagonal and below to 0
~ % Negate each entry. Implicit display
added 114 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
added 12 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
added 12 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
deleted 2 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
added 482 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading

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