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

Reduce byte count thanks to Zachary's suggestion.
Source Link
lstefano
  • 920
  • 5
  • 6

APL, 32(削除) 32 (削除ここまで) 31 chars

{⍺=0:(⍴⍵)⍴(1+≢⍵)↑1⋄+⍴1⍨1+≢⍵⋄+×ばつ⍨⍣(⍺-1)⊣⍵}

Left argument the power to raise to, right argument the matrix The. The hardest (most space consuming) bit is building the identity matrix for the case where the desired exponent is 0. The actual computation is based on the fact that the generalised inner product (.) with + and ×ばつ as operands is effectively the matrix product. This combined with the power operator ("repeat") forms the meat of the solution.

APL, 32 chars

{⍺=0:(⍴⍵)⍴(1+≢⍵)↑1⋄+×ばつ⍨⍣(⍺-1)⊣⍵}

Left argument the power to raise to, right argument the matrix The hardest (most space consuming) bit is building the identity matrix for the case where the desired exponent is 0. The actual computation is based on the fact that the generalised inner product (.) with + and ×ばつ as operands is effectively the matrix product. This combined with the power operator ("repeat") forms the meat of the solution.

APL, (削除) 32 (削除ここまで) 31 chars

{⍺=0:(⍴⍵)⍴1⍨1+≢⍵⋄+×ばつ⍨⍣(⍺-1)⊣⍵}

Left argument the power to raise to, right argument the matrix. The hardest (most space consuming) bit is building the identity matrix for the case where the desired exponent is 0. The actual computation is based on the fact that the generalised inner product (.) with + and ×ばつ as operands is effectively the matrix product. This combined with the power operator ("repeat") forms the meat of the solution.

Source Link
lstefano
  • 920
  • 5
  • 6

APL, 32 chars

{⍺=0:(⍴⍵)⍴(1+≢⍵)×ばつ⍨⍣(⍺-1)⊣⍵}

Left argument the power to raise to, right argument the matrix The hardest (most space consuming) bit is building the identity matrix for the case where the desired exponent is 0. The actual computation is based on the fact that the generalised inner product (.) with + and ×ばつ as operands is effectively the matrix product. This combined with the power operator ("repeat") forms the meat of the solution.

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