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 36 characters in body
Source Link
Giuseppe
  • 29.4k
  • 3
  • 33
  • 106

R, 65(削除) 65 (削除ここまで) 63 bytes

f=function(n)"if"(n,kronecker(matrix(c(0,34:1)1%%4,2),4*f(n-1),"+"),0)

Try it online! Try it online!

-2 bytes thanks to pajonk.

Recursive function. Takes \$log_2(s)\$ as an input and returns the corresponding \$s\times s\$ matrix as output. 24 bytes shorter than using rbind and cbind:.

R, 67 bytes

f=function(n)"if"(n,cbind(rbind(g<-4*f(n-1),g+3),rbind(g+2,g+1)),0)

Try it online!

R, 65 bytes

f=function(n)"if"(n,kronecker(matrix(c(0,3:1),2),4*f(n-1),"+"),0)

Try it online!

Recursive function. Takes \$log_2(s)\$ as an input and returns the corresponding \$s\times s\$ matrix as output. 2 bytes shorter than using rbind and cbind:

R, 67 bytes

f=function(n)"if"(n,cbind(rbind(g<-4*f(n-1),g+3),rbind(g+2,g+1)),0)

Try it online!

R, (削除) 65 (削除ここまで) 63 bytes

f=function(n)"if"(n,kronecker(matrix(4:1%%4,2),4*f(n-1),"+"),0)

Try it online!

-2 bytes thanks to pajonk.

Recursive function. Takes \$log_2(s)\$ as an input and returns the corresponding \$s\times s\$ matrix as output. 4 bytes shorter than using rbind and cbind.

R, 67 bytes

f=function(n)"if"(n,cbind(rbind(g<-4*f(n-1),g+3),rbind(g+2,g+1)),0)

Try it online!

Source Link
Giuseppe
  • 29.4k
  • 3
  • 33
  • 106

R, 65 bytes

f=function(n)"if"(n,kronecker(matrix(c(0,3:1),2),4*f(n-1),"+"),0)

Try it online!

Recursive function. Takes \$log_2(s)\$ as an input and returns the corresponding \$s\times s\$ matrix as output. 2 bytes shorter than using rbind and cbind:

R, 67 bytes

f=function(n)"if"(n,cbind(rbind(g<-4*f(n-1),g+3),rbind(g+2,g+1)),0)

Try it online!

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