[Question]
  [
# The Challenge
Given an integer `n>0` output a `n+1 X n+1` matrix containing all integers from `1` to `2n` as shown in the test cases bellow
# Test Cases
```
n=1  
1  2  
2  2
n=2
1   2   4  
2   3   4  
4   4   4
n=5  
1   2   3   4   5   10  
2   3   4   5   6   10  
3   4   5   6   7   10   
4   5   6   7   8   10  
5   6   7   8   9   10  
10  10  10  10  10  10  
n=10  
1   2   3   4   5   6   7   8   9   10  20  
2   3   4   5   6   7   8   9   10  11  20  
3   4   5   6   7   8   9   10  11  12  20  
4   5   6   7   8   9   10  11  12  13  20  
5   6   7   8   9   10  11  12  13  14  20  
6   7   8   9   10  11  12  13  14  15  20  
7   8   9   10  11  12  13  14  15  16  20  
8   9   10  11  12  13  14  15  16  17  20  
9   10  11  12  13  14  15  16  17  18  20  
10  11  12  13  14  15  16  17  18  19  20  
20  20  20  20  20  20  20  20  20  20  20  
```
I think that the pattern is pretty easy, so let's see who will give the shortest answer in bytes.  
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'")
# Rules
**Input** must be an integer (**1-indexed**)
**Output** can be a **matrix** (as shown in the test cases) or a **list of lists**
  
[Answer]
# [R](https://www.r-project.org/), 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 `bind`s `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!](https://tio.run/##K/qfZvs/rTQvuSQzP08jT7MoKTMvRSMZTOaXlqQWaRha5emAcIJ2gqauoY6RVp4mmPifpmGk@R8A "R – Try It Online")
# [R](https://www.r-project.org/), 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!](https://tio.run/##K/qfZvs/rTQvuSQzP08jT7M61zY3saQos0LDSCtPJ0/bEIQ1udLyizQyFTLzFIpTC4GqNHOjDa3ydDJjbTUMrEAqNTVBAtqZsVy5tf/TNEA6NEw1/wMA "R – Try It Online")
[Answer]
# Mathematica, ~~61~~ 46 bytes
```
ArrayFlatten@{{##-1&~Array~{#,#},2#},{2#,2#}}&
```
thanx @alephalpha for -15 bytes
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~12~~ 10 bytes
```
:&+q,!GEYc
```
[Try it online!](https://tio.run/##y00syfn/30pNu1BH0d01Mvn/f0MDAA)
### Explanation
```
:       % Input n (implicit). Push range [1 2 ... n]
&+      % matrix of pairwise additions
q       % Subtract 1
,       % Do twice
  !     %   Transpose
  GE    %   Push 2*n
  Yc    %   Concatenate that value to all rows, thus extending the matrix
        % End (implicit). Display (implicit)
```
[Answer]
# [Haskell](https://www.haskell.org/), 48 bytes
```
f n=[[i..n-1+i]++[2*n]|i<-[1..n]]++[2*n<$[0..n]]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00hzzY6OlNPL0/XUDszVls72kgrL7Ym00Y32hAoGAsVsVGJNgBz/@cmZuYp2CrkJhb4KhQUZeaVaKQpGBpo/gcA "Haskell – Try It Online")
[Answer]
# Octave, ~~38~~ ~~37~~ 35 bytes
```
@(n)[(x=1:n)+x'-1 z=~x'+2*n;z' 2*n]
```
[Try it online!](https://tio.run/##y08uSSxL/f/fQSNPM1qjwtbQKk9Tu0Jd11ChyrauQl3bSCvPukpdAUjF/k/MK9Yw1fwPAA "Octave – Try It Online")
or
```
@(n)~(k=blkdiag((x=1:n)+x'-1,0))*2*n+k
```
[Try it online!](https://tio.run/##y08uSSxL/f/fQSNPs04j2zYpJzslMzFdQ6PC1tAqT1O7Ql3XUMdAU1PLSCtPO/t/Yl6xhqnmfwA "Octave – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 11 bytes
```
+þḶ;€Ḥ;ḤzḤG
```
[Try it online!](https://tio.run/##y0rNyan8/1/78L6HO7ZZP2pa83DHEmsgrgJi9////5sCAA "Jelly – Try It Online")
[Answer]
## JavaScript (ES6), 64 bytes
```
f=
n=>[...Array(n+1)].map((_,i,a)=>a.map((_,j)=>n-i&&n-j?i-~j:n+n))
```
```
<input type=number min=0 oninput="t.innerHTML=f(+this.value).map(a=>`<tr>${a.map(b=>`<td>${b}</td>`).join``}</tr>`).join``"><table id=t>
```
[Answer]
# Java 8, 99 bytes
Lambda from `Integer` to `int[][]` (e.g. `Function<Integer, int[][]>`). Surprisingly resistant to golfing.
```
n->{int p=n+1,o[][]=new int[p][p],i=0,r,c;while(i<p*p)o[r=i/p][c=i++%p]=r<n&c<n?r-~c:2*n;return o;}
```
[Try It Online](https://tio.run/##XZBNa8MwDIbP6a/QZSNpU@8Ddmnijl0GO/SyHkMOnutk6lzZOEq7Urq/nrkfMBjoIHj1Ss@rtdqqqfOG1quvwfcfFjVoq7oOFgoJDqPEB9wqNtCx4ig2SMrCOtpEz2hF05NmdCRer035RmxaE3JA4qqu6jm0ht8VtWahOOA3yIGm80NUwUuaPOTuNCXJ7M4OX8fKUd7nIdfF7hOtSbH0Y5@5Kki8i7qWOJnc@FqGkm51Sc9h@qNnj2MqguE@ELjiOCTFKMJfEl3Ztw5XsIm50mUEobaqQYW2y04xk8YFSM/IENwOZv@ohfLe7tOn7DKdLPcdm41wPYv4IWJL6d9TXkJQ@06wu9xJ48IsK6LtOIp1HH4B)
## Ungolfed lambda
```
n -> {
    int
        p = n + 1,
        o[][] = new int[p][p],
        i = 0,
        r, c
    ;
    while (i < p * p)
        o[r = i / p][c = i++ % p] =
            r < n & c < n ?
                r - ~c
                : 2 * n
        ;
    return o;
}
```
## Acknowledgments
* -1 byte thanks to Kevin Cruijssen
[Answer]
# [Python 2](https://docs.python.org/2/), ~~64~~ ~~62~~ 61 bytes
*-3 bytes thanks to Mr. Xcoder.*
```
lambda n:[range(i+1,i-~n)+[n*2]for i in range(n)]+[[n*2]*-~n]
```
[Try it online!](https://tio.run/##PcuxDoMgFEbh3af4RxGaCImLCU9CGTCK3qS9EmTp0ldHY5PO3znpU7adTY32WV/hPc0BPLoceF1aklrR48tCOu6Mj3sGgRg/ZeGlu6G7Gl/LcpQDFk4rGIVBQfe@af7X7SNSJi6ILYl6Ag "Python 2 – Try It Online")
I'm probably missing a key pattern though.
# [Python 2](https://docs.python.org/2/), 76 bytes
```
lambda n:[[[n*2,i-~j][n-i and n-j>0]for j in range(n+1)]for i in range(n+1)]
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHPKjo6Ok/LSCdTty4rNjpPN1MhMS9FIU83y84gNi2/SCFLITNPoSgxLz1VI0/bUBMslokm9r@gKDOvRCFNw1TzPwA "Python 2 – Try It Online")
[Answer]
# [Pyth](https://pyth.readthedocs.io), 18 bytes
```
+m+rd+QdyQSQ]*]yQh
```
Maybe I am missing an obvious pattern (cc [@totallyhuman](https://codegolf.stackexchange.com/a/140824/59487))...
**[Test Suite.](https://pyth.herokuapp.com/?code=%2Bm%2Brd%2BQdyQSQ%5D%2a%5DyQh&input=1%0A2%0A3%0A4%0A5&test_suite=1&test_suite_input=1%0A2%0A5%0A10&debug=0)**
**["Pretty print" Test Suite.](https://pyth.herokuapp.com/?code=j%2Bm%2Brd%2BQdyQSQ%5D%2a%5DyQh&input=1%0A2%0A3%0A4%0A5&test_suite=1&test_suite_input=1%0A2%0A5%0A10&debug=0)**
[Answer]
# [Proton](https://github.com/alexander-liao/proton), ~~48~~ 44 bytes
*-4 bytes thanks to @totallyhuman!*
```
n=>[(i+1..i-~n)+[n*2]for i:0..n]+[[n*2]*-~n]
```
[Try it online!](https://tio.run/##KyjKL8nP@59m@z/P1i5aI1PbUE8vU7cuT1M7Ok/LKDYtv0gh08pATy8vVjsaLKIFlIz9X1CUmVeikaZhqKnJBWMbIbFNkdiGBpqa/wE "Proton – Try It Online")
[Answer]
# [R](https://www.r-project.org/), 54 ~~63~~ ~~67~~ bytes
```
function(n)cbind(rbind(sapply(1:n-1,'+',1:n),2*n),2*n)
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP08jTzM5KTMvRaMITBYnFhTkVGoYWuXpGuqoa6vrAFmaOkZaUOJ/moaRJleahimIMDTQ/A8A "R – Try It Online")
Thanks to @Guiseppe for the pointer for sapply and the 9 bytes
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~17~~ 16 bytes
```
õ_óU pU*2ÃpUô@*2
```
[Try it online!](https://tio.run/##y0osKPn///DW@MObQxUKQrWMDjcXhB7e4qBl9P@/qYJuIAA "Japt – Try It Online")
[Answer]
# [Recursiva](https://github.com/officialaimm/recursiva), 50 bytes
* Only 10 bytes shorter than python and thus it is official, Recursiva is not a golfing-language at all... It is an esolang though. :D
```
|{Ba+++++'PJ"	"W+Z~}B+~}'Va'+}'Va'AD'VaJ"	"W*;aADa
```
[Try it online!](https://tio.run/##K0pNLi0qzixL/P@/ptopURsE1AO8lDiVwrWj6mqdtOtq1cMS1bXBpKMLkATLaVknOroA9RgaAAA "Recursiva – Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~119~~ ~~116~~ ~~115~~ 107 bytes
```
i,j;f(n){for(;j<n;j++,printf("%d\n",2*n))for(i=0;i++<n;printf("%d\t",j+i));for(;j=i--;printf("%d\t",n*2));}
```
[Try it online!](https://tio.run/##fc1BCsIwEIXhfU4hASHTpJAEuhp7EzdSiUzAsdS4Kj17TFVoFWmW//uYdPWl63ImEzEohjHcBoXxwBi1Nv1AnIKS@/ORpfEVA8w7tRZJ64JWIEkTNQHg@0JLdf0zc@XLPOXriViBGMWuvP6R7kpy6yTgKwTlAD@5tDl9Qb9AvwmbBTab0NnV3/YvFZPITw "C (gcc) – Try It Online")
[Answer]
# [Röda](https://github.com/fergusq/roda), 44 bytes
```
f n{seq 1,n|[[seq(_,_1+n-1)]+2*n];[[2*n]*n]}
```
[Try it online!](https://tio.run/##K8pPSfz/P00hr7o4tVDBUCevJjoayNKI14k31M7TNdSM1TbSyou1jo4GUUBU@z83MTNPoZqLM03DVFOhRqGgKDOvRCNek6v2PwA "Röda – Try It Online")
Explanation:
```
f n{seq 1,n|[[seq(_,_1+n-1)]+2*n];[[2*n]*n]}
f n{                                       } /* Function f(n)         */
    seq 1,n                                  /* Sequence 1..n         */
           |                                 /* For each _1:          */
              seq(_,_1+n-1)                  /*   Sequence _1.._1+n-1 */
             [             ]                 /*   As list             */
                            +2*n             /*   Append 2*n          */
            [                   ]            /*   Push to the stream  */
                                   [2*n]     /* List [2*n]            */
                                        *n   /* Multiplied by n       */
                                  [       ]  /* Push to the stream    */
```
[Answer]
# Dyalog APL, 29 bytes
Requires `⎕IO←0`
```
{(S,⍨1+¯1 ¯1↓∘.+⍨⍳⍵+1)⍪S←2×⍵}
```
[Try it online!](http://tryapl.org/?a=%u2395IO%u21900%u22C4%7B%28S%2C%u23681+%AF1%20%AF1%u2193%u2218.+%u2368%u2373%u2375+1%29%u236AS%u21902%D7%u2375%7D5&run)
## How?
* `1+¯1 ¯1↓∘.+⍨⍳⍵+1` the upper-left portion of the array
* `(S,⍨...)⍪S←2×⍵` the corner
[Answer]
# ><>, 84+2 Bytes
+2 for -v flag
Prints with tabs between values, and newlines between rows. Also prints a trailing tab on the last line. 
[Try it online](https://tio.run/##S8sszvj/39CqyEqtSE3TPsYAwtKwj6lTsXIw0spLzDfUVuRKNNDTB8oY1NnoGZprG@ZbxijEAOWBSDvPEqiCS0FBIQZsgjVEm4L@////dcsUDA0A)
```
1:r:&r&)?\0:r:&r&(?\~$:@2*nao1+!
a0./:r:0~<.17+1o9\ \$:@$:@+n9o1+
   \&r&)?;$:@2*n /
```
## Pre-golfing
```
1>:r:&r&)?\0>    :r:&r&(?\~$:@2*nao1+\
            \+1o9n+@:$@:$/
 \                                   /
          \~0>:r:&r&)?;$:@2*n9o1+\
             \                   /
```
[Answer]
# [SOGL V0.12](https://github.com/dzaima/SOGL), 22 [bytes](https://github.com/dzaima/SOGL/blob/master/chartable.md)
```
∫HA.∫a+}.«¹}¹.I.«r∙rο+
```
[Try it Here!](https://dzaima.github.io/SOGLOnline/?code=JXUyMjJCSEEuJXUyMjJCYSslN0QuJUFCJUI5JTdEJUI5LkkuJUFCciV1MjIxOXIldTAzQkYr,inputs=NQ__)  
leaves output on the stack, which you can view in the console
[Answer]
# Jelly, 14 bytes
```
R+’r@R;€Ḥz0;€Ḥ
```
[Try it online!](https://tio.run/##y0rNyan8/z9I@1HDzCKHIOtHTWse7lhSZQBluP///98UAA)
[Answer]
# [Perl 5](https://www.perl.org/), 56 bytes
```
$,=$";say($_..$_+$"-1,$"*2)for 1..($"=<>);say(($"*2)x$")
```
[Try it online!](https://tio.run/##K0gtyjH9/19Fx1ZFybo4sVJDJV5PTyVeW0VJ11BHRUnLSDMtv0jBUE9PQ0XJ1sZOE6xGAyxRoaKk@f@/6b/8gpLM/Lzi/7q@pnoGhgYA "Perl 5 – Try It Online")
[Answer]
# [Kotlin](https://kotlinlang.org), 59 bytes
```
Array(n+1){c->Array(n+1){r->when(n){c,r->n*2;else->1+c+r}}}
```
[Try it online.](https://tio.run/##rZDLCoMwEEX3fsXgKtEqjdBNH4Euuui6XxDER1qdSIx9IPn2NFgE93V2l3vPWcxDmUaik22ntIG7eIp0MLJJoyAoB4RWSCRCV/0ezlqLz/FmtMSKUxgD8NcKn9@E0bRU@iLyGkaAzk9Mg2Qi@tSoH0SkoRTATuC8CUO6FGVriXZridj2L5Od/zjJcA9XNBRObuIJxoyOecIXSSf8VRdI0BcbHzDKDkXTFwlncR5ra61zXw "Kotlin – Try It Online")
[Answer]
# Clojure, 153 135 bytes
List of lists? Yay, Lisp
```
(fn[n](loop[r[] i 0 d (* 2 n)](if(= i n)(conj r(conj(repeat n d)d))(recur(conj r(conj(vec(map #(+ i %)(range 1(inc n))))d))(inc i)d))))
```
Ungolfed:
```
(defn a[n]
  (loop [r[] i 0 d (* 2 n)]
    (if(= i n)
      (conj r(conj(repeat n d)d))
      (recur
        (conj r
            (conj (vec (map #(+ i %)(range 1(inc n)))) d))
        (inc i)
        d))))
```
Anonymous function that takes the input as argument and returns a list of lists. 
Output of n=5:
```
[[1 2 3 4 5 10] [2 3 4 5 6 10] [3 4 5 6 7 10] [4 5 6 7 8 10] [5 6 7 8 9 10] (10 10 10 10 10 10)]
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 17 bytes
```
FLN+I·¸«ˆ}·¸I>.×ˆ
```
[Try it online!](https://tio.run/##MzBNTDJM/f/fzcdP2/PQ9kM7Dq0@3VYLYnja6R2efrrt/39TAA "05AB1E – Try It Online")
**Explanation**
```
F                   # for N in [0 ... input-1]
 L                  # push range [1 ... input]
  N+                # add N to each
    I·¸«            # append input*2
        ˆ           # add to global list
         }          # end loop
          ·¸        # push [input*2]
            I>.×    # repeat it input+1 times
                ˆ   # add to global list
                    # implicitly output global list
```
[Answer]
# J, 29 bytes
```
(}:@(][\1+i.@+:),]#+:),.>:#+:
```
## ungolfed
```
(}:@(] [\ 1+i.@+:) , ]#+:) ,. >:#+:
```
## explanation
```
(}:@(] [\ 1+i.@+:)                   NB. make the inner part of the matrix
          1+i.@+:                      NB. 1..2*n, where n is the input
    (] [\ 1+i.@+:)                     NB. fork: infixes (sliding window) of length n, over 1..2*n
(}:@                                   NB. remove last element
                   , ]#+:)           NB. add a row of 2*n to the end
                           ,. >:#+:  NB. add a column of 2*n to entire result above
```
[Try it online!](https://tio.run/##y/r/P81WT0Gj1spBI1YhOkbBUDtTz0HbSlNBRyFWGUzrKdhZAVlcqckZ@QppCoYQhro6TMAIXcD0/38A "J – Try It Online")
[Answer]
# [Actually](https://github.com/Mego/Seriously), 23 bytes
```
;;Rnkp@;r♀+@;τ;(♀q)@α@q
```
[Try it online!](https://tio.run/##S0wuKU3Myan8/9/aOigvu8DBuujRzAZtB@vzLdYaQFahpsO5jQ6F//@bAgA "Actually – Try It Online")
Explanation:
```
;;Rnkp@;r♀+@;τ;(♀q)@α@q
;;                       two copies of input
  R                      range(1, input+1)
   n                     copy input times
    kp@                  push stack to list, remove first element
       ;r                push range(input)
         ♀+              pairwise addition (add the value in the range to each value in the corresponding list)
           @;            duplicate input again
             τ;          input*2, duplicate that
               (♀q)      append input*2 to each list
                   @α@q  append a row of input*2
```
[Answer]
# [Clojure](https://clojure.org/) v1.8, 97 bytes
```
#(conj(mapv(fn[i](conj(vec(range i(+ % i)))(* 2 %)))(range 1(inc %)))(vec(repeat(inc %)(* 2 %))))
```
[Try it online!](https://repl.it/Kotn/0)
# Explanation
```
(range 1(inc %))                           Numbers from 1 to 'n'
(mapv ... (range 1(inc %)))                For each one of these numbers
(fn[i](conj(vec(range i(+ % i)))(* 2 %)))  Create the numbers from 'i' to (n+i-1), convert to vector and insert '2*n' to the vector
#(conj ... (vec(repeat(inc %)(* 2 %))))    Insert to the previous vector a vector of repeated '2*n's
```
[Answer]
# [Fortran (GFortran)](https://gcc.gnu.org/fortran/), 93, 82 bytes
```
SUBROUTINE M(n)
PRINT*,(CHAR(10),(i-1+j,i=1,n),2*n,j=1,n)
PRINT*,(2*n,j=1,n+1)
END
```
[Try it online!](https://tio.run/##S8svKilKzNNNT4Mw/gcE@bsHOfoqOHM5O/r4KPhqGGrCWEZwlimcZWigyeXq5/I/ONQpyD80xNPPFSiYp8kVEOTpF6Klo@Hs4RgEUqSjkalrqJ2lk2lrqJOnqWOklaeTBWbCVcKFtA0hRv4HAA "Fortran (GFortran) – Try It Online")
]