Husk, (削除) 12 11 (削除ここまで) 10 bytes
≡1 ́Ṫ§^*=l·L
Explanation
≡1 ́Ṫ§^*=l·L Input is a k×ばつk array A.
L The length, k.
l· The range [0,1..k-1].
́Ṫ Outer product with itself by this function:
Arguments are two numbers x and y.
= Equality of x and y
§^ to the power of
* x times y.
≡1 Does the result have the same shape and distribution of truthy values as A?
The idea is that Husk defines 0 to the power of 0 as 1, so the outer product has 1s on the first row and column.
Also, 1 to the power of any number is 1, so the outer product has 1s on the diagonal.
Other entries are 0 to the power of some positive number, which is 0.
This gives a binary arrowhead matrix, which we compare to the input with ≡.
Zgarb
- 43.2k
- 4
- 84
- 265