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

deleted 9 characters in body
Source Link
Zgarb
  • 43.2k
  • 4
  • 84
  • 265

Husk, (削除) 12 11 (削除ここまで) 1110 bytes

S≡ȯ ́Ṫ§^*=l·L≡1 ́Ṫ§^*=l·L

Try it online! Try it online!

Explanation

S≡ȯ ́Ṫ§^*=l·L≡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.
S≡ ≡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 .

Husk, (削除) 12 (削除ここまで) 11 bytes

S≡ȯ ́Ṫ§^*=l·L

Try it online!

Explanation

S≡ȯ ́Ṫ§^*=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.
S≡  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 .

Husk, (削除) 12 11 (削除ここまで) 10 bytes

≡1 ́Ṫ§^*=l·L

Try it online!

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 .

deleted 64 characters in body
Source Link
Zgarb
  • 43.2k
  • 4
  • 84
  • 265

Husk, 12(削除) 12 (削除ここまで) 11 bytes

S≡o ́Ṫ§oε%=▼l·S≡ȯ ́Ṫ§^*=l·L

Try it online! Try it online!

Explanation

S≡o ́Ṫ§oε%=▼l·S≡ȯ ́Ṫ§^*=l·L Input is a k×ばつk array A.
 L The length, k.
 l· The range [1[0,21..k]k-1].
 o ́Ṫ ȯ ́Ṫ Outer product with itself by this function:
 Arguments are two numbers x and y.
 =  MinimumEquality of x and y
 §^ §% modulo
to the power of
 = * equality of x andtimes y.
 oε Is it at most 1?
S≡ Does the result have the same shape and distribution of truthy values as A?

This program slightly abuses the wayThe idea is that Husk implementsdefines 0 to the modulo function %. Any number modulo 1 ispower of 0 as 1, so the outer product has 1s on the diagonal x=y we have zerosfirst row and column. On the other handAlso, 1 to the power of any numbern modulo 0 is n1, so we havethe outer product has 1s on the first row and column, since min(x,y)=1 there, and in other positionsdiagonal. Other entries are 0 to the valuepower of some positive number, which is greater than 10. Applying εThis gives a binary arrowhead matrix, which we compare to the input with .

Husk, 12 bytes

S≡o ́Ṫ§oε%=▼l·

Try it online!

Explanation

S≡o ́Ṫ§oε%=▼l· Input is a k×ばつk array A.
 l· The range [1,2..k]
 o ́Ṫ Outer product with itself by this function:
 Arguments are two numbers x and y.
  Minimum of x and y
 §% modulo
 = equality of x and y.
 oε Is it at most 1?
S≡ Does the result have the same shape and distribution of truthy values as A?

This program slightly abuses the way Husk implements the modulo function %. Any number modulo 1 is 0, so on the diagonal x=y we have zeros. On the other hand, any numbern modulo 0 is n, so we have 1s on the first row and column, since min(x,y)=1 there, and in other positions the value is greater than 1. Applying ε gives a binary arrowhead matrix, which we compare to the input with .

Husk, (削除) 12 (削除ここまで) 11 bytes

S≡ȯ ́Ṫ§^*=l·L

Try it online!

Explanation

S≡ȯ ́Ṫ§^*=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.
S≡ 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 .

added 458 characters in body
Source Link
Zgarb
  • 43.2k
  • 4
  • 84
  • 265

Husk, 12 bytes

S≡o ́Ṫ§oε%=▼l·

Try it online!

Explanation

S≡o ́Ṫ§oε%=▼l· Input is a k×ばつk array A.
 l· The range [1,2..k]
 o ́Ṫ Outer product with itself by this function:
 Arguments are two numbers x and y.
 ▼ Minimum of x and y
 §% modulo
 = equality of x and y.
 oε Is it at most 1?
S≡ Does the result have the same shape and distribution of truthy values as A?

This program slightly abuses the way Husk implements the modulo function %. Any number modulo 1 is 0, so on the diagonal x=y we have zeros. On the other hand, any number n modulo 0 is n, so we have 1s on the first row and column, since min(x,y)=1 there, and in other positions the value is greater than 1. Applying ε gives a binary arrowhead matrix, which we compare to the input with .

Husk, 12 bytes

S≡o ́Ṫ§oε%=▼l·

Try it online!

Explanation

S≡o ́Ṫ§oε%=▼l· Input is a k×ばつk array A.
 l· The range [1,2..k]
 o ́Ṫ Outer product with itself by this function:
 Arguments are two numbers x and y.
 ▼ Minimum of x and y
 §% modulo
 = equality of x and y.
 oε Is it at most 1?
S≡ Does the result have the same shape and distribution of truthy values as A?

Husk, 12 bytes

S≡o ́Ṫ§oε%=▼l·

Try it online!

Explanation

S≡o ́Ṫ§oε%=▼l· Input is a k×ばつk array A.
 l· The range [1,2..k]
 o ́Ṫ Outer product with itself by this function:
 Arguments are two numbers x and y.
 ▼ Minimum of x and y
 §% modulo
 = equality of x and y.
 oε Is it at most 1?
S≡ Does the result have the same shape and distribution of truthy values as A?

This program slightly abuses the way Husk implements the modulo function %. Any number modulo 1 is 0, so on the diagonal x=y we have zeros. On the other hand, any number n modulo 0 is n, so we have 1s on the first row and column, since min(x,y)=1 there, and in other positions the value is greater than 1. Applying ε gives a binary arrowhead matrix, which we compare to the input with .

added 458 characters in body
Source Link
Zgarb
  • 43.2k
  • 4
  • 84
  • 265
Loading
Source Link
Zgarb
  • 43.2k
  • 4
  • 84
  • 265
Loading

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