Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
function(n)cbind(rbind(sapply(1:n-1,function(x)x+1'+',1:n),2*n),2*n)
Try it online!Try it online!
Thanks to @Guiseppe for the pointer for sapply and the 9 bytes
function(n)cbind(rbind(sapply(1:n-1,function(x)x+1:n),2*n),2*n)
Try it online!
function(n)cbind(rbind(sapply(1:n-1,'+',1:n),2*n),2*n)
function(n)cbind(rbind(sapply(1:n-1,function(x)x:(xx+1:x+n-1)n),2*n),2*n)
Might still have a bit of room for golfing.Try it online!
function(n)cbind(rbind(sapply(1:n,function(x)x:(x:x+n-1)),2*n),2*n)
Might still have a bit of room for golfing.