Skip to main content
added 3 characters in body
Source Link
Giuseppe
  • 29.4k
  • 3
  • 33
  • 106

R, 5454 42 bytes

-12 bytes thanks to Jarko Dubbeldam

n=scan();m=diag(n)[,n:1];m[1,1]=m[n,n]=1;write(m,'',n)n]=1;m 

prints to stdout;returns a matrix; reads from stdin. creates an identity matrix diag(n), flips it top to bottom [,n:1], sets the top left and bottom right to 1, and then writes to console ('') with width n.

Try it online!Try it online!

R, 54 bytes

n=scan();m=diag(n)[,n:1];m[1,1]=m[n,n]=1;write(m,'',n) 

prints to stdout; reads from stdin. creates an identity matrix diag(n), flips it top to bottom [,n:1], sets the top left and bottom right to 1, and then writes to console ('') with width n.

Try it online!

R, 54 42 bytes

-12 bytes thanks to Jarko Dubbeldam

n=scan();m=diag(n)[,n:1];m[1,1]=m[n,n]=1;m 

returns a matrix; reads from stdin. creates an identity matrix diag(n), flips it top to bottom [,n:1], sets the top left and bottom right to 1, and then writes to console ('') with width n.

Try it online!

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

R, 54 bytes

n=scan();m=diag(n)[,n:1];m[1,1]=m[n,n]=1;write(m,'',n) 

prints to stdout; reads from stdin. creates an identity matrix diag(n), flips it top to bottom [,n:1], sets the top left and bottom right to 1, and then writes to console ('') with width n.

Try it online!