Skip to main content
added 238 characters in body
Source Link
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105

R, 53 bytes

function(n)rbind(cbind(outer(1:n,1:n,`+`)-1,2*n),2*n)

Uses the outer "product" to generate all sums of the range 1,...,n as a matrix, subtracts 1 from each, then binds 2*n as a column on the right and a row on the bottom, recycling as needed, and returns a matrix as the result.

Try it online!

R, 78 bytes

More naive implementation.

function(n){m=matrix(2*n,n+1,n+1)
for(i in seq(n))m[1:n,i]=(0:(2*n))[1:n+i]
m}

Try it online!

R, 53 bytes

function(n)rbind(cbind(outer(1:n,1:n,`+`)-1,2*n),2*n)

Try it online!

R, 78 bytes

More naive implementation.

function(n){m=matrix(2*n,n+1,n+1)
for(i in seq(n))m[1:n,i]=(0:(2*n))[1:n+i]
m}

Try it online!

R, 53 bytes

function(n)rbind(cbind(outer(1:n,1:n,`+`)-1,2*n),2*n)

Uses the outer "product" to generate all sums of the range 1,...,n as a matrix, subtracts 1 from each, then binds 2*n as a column on the right and a row on the bottom, recycling as needed, and returns a matrix as the result.

Try it online!

R, 78 bytes

More naive implementation.

function(n){m=matrix(2*n,n+1,n+1)
for(i in seq(n))m[1:n,i]=(0:(2*n))[1:n+i]
m}

Try it online!

added 280 characters in body
Source Link
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105

R, 7853 bytes

function(n)rbind(cbind(outer(1:n,1:n,`+`)-1,2*n),2*n)

Try it online!

R, 78 bytes

More naive implementation.

function(n){m=matrix(2*n,n+1,n+1)
for(i in seq(n))m[1:n,i]=(0:(2*n))[1:n+i]
m}

Try it online!

R, 78 bytes

function(n){m=matrix(2*n,n+1,n+1)
for(i in seq(n))m[1:n,i]=(0:(2*n))[1:n+i]
m}

Try it online!

R, 53 bytes

function(n)rbind(cbind(outer(1:n,1:n,`+`)-1,2*n),2*n)

Try it online!

R, 78 bytes

More naive implementation.

function(n){m=matrix(2*n,n+1,n+1)
for(i in seq(n))m[1:n,i]=(0:(2*n))[1:n+i]
m}

Try it online!

Source Link
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105

R, 78 bytes

function(n){m=matrix(2*n,n+1,n+1)
for(i in seq(n))m[1:n,i]=(0:(2*n))[1:n+i]
m}

Try it online!