g | x | w | all
Bytes Lang Time Link
049Clojure240906T105223ZNikoNyrh
184Oracle SQL 11.2240905T151026ZJeto
045F# .NET Core240905T050135Zdtanku
008Pyth240821T160302Zint 21h
033Arturo230117T011748Zchunes
004Husk210611T092216ZDominic
037Perl 5 + M5.10.0 na231120T092503ZDom Hast
052JavaScript Node.js231115T021507Zl4m2
016RProgN 2231115T015831ZATaco
002Vyxal231114T235605Zlyxal
039Perl 5231114T234331ZXcali
006Uiua231114T212505Zchunes
075JavaScript Node.js230718T093752ZFhuvi
004Thunno 2230714T142931ZThe Thon
038Excel Office 365 Insider Preview220313T015604ZTaylor R
044Excel VBA220309T203434ZEngineer
012Pyth220309T181739Zsinvec
026Pari/GP211201T012836Zalephalp
122Nim210930T235753ZQaziquza
005ayr211201T144106ZZippyMag
004Vyxal 2.6.0 r211201T110337Zlyxal
084Rust211201T084408ZEzhik
041TIBasic210930T224219ZYouserna
052Python210915T140326ZLarry Ba
080Regenerate210628T201632ZDLosc
277TSQL210628T135259ZLiefdeWe
049Python 3210613T205143ZKyuuhach
9389<>^v210611T150735Zastroide
067Python 3210612T065432Zuser1045
016Wolfram Language Mathematica210611T214326ZGreg Mar
028Haskell210611T211222Zxnor
00605AB1E210611T164155ZMakonede
069PHP F210611T143748ZKaddath
048Python 2210611T115700ZElPedro
056JavaScript Node.js210610T183228Zuser1007
070C# Visual C# Interactive Compiler210611T093914ZLiefdeWe
084Java JDK210611T082509ZOlivier
005Japt210610T170213ZShaggy
035Ruby210611T050243ZG B
006Vyxal210611T042759Zemanresu
049Python 3210611T035134Zatt
040PowerShell Core210611T032831ZJulian
035Factor210611T025535Zchunes
003Stax210611T025507ZRazetime
019Octave210611T024808Ztsh
030R210610T202338Zpajonk
065C gcc210610T194119Zdingledo
011Charcoal210610T192633ZNeil
077C clang210610T182302ZNoodle9
010K ngn/k210610T190457Zcoltim
019Julia210610T184516ZMarcMush
096Posix SH + sed210610T175639ZWezl
015Vyxal210610T174043ZWasif
085JavaScript Node.js210610T173403Zuser1006
050Python 2210610T165642Zhyper-ne
009J210610T171717ZConor O&
011APL Dyalog Unicode210610T170242ZWasif
005APL Dyalog Unicode210610T164902ZAdá
002Jelly210610T164853Zcaird co

Clojure, 49 bytes

#(for[R[(range 1(inc %))]r R](for[c R](max r c)))

TIO. IMO the only interesting trick is to re-use the range value R.

Oracle SQL 11.2, 184 bytes

WITH v AS(SELECT LEVEL l FROM DUAL CONNECT BY LEVEL<=:1)SELECT DISTINCT LISTAGG(DECODE(SIGN(a.l-b.l),1,a.l,b.l))WITHIN GROUP(ORDER BY a.l)OVER(PARTITION BY b.l)FROM v a,v b ORDER BY 1;

Un-golfed

WITH v AS(SELECT LEVEL l FROM DUAL CONNECT BY LEVEL<=:1)
SELECT DISTINCT LISTAGG(DECODE(SIGN(a.l-b.l),1,a.l,b.l))WITHIN GROUP(ORDER BY a.l)OVER(PARTITION BY b.l)
FROM v a, v b
ORDER BY 1;

F# (.NET Core), 45 bytes

let a n=Array2D.init n n (fun i j->max i j+1)

Try it online!

F#'s built-in array initializers come in clutch here (cf. the C# answers).

Pyth, 8 bytes

VQmhg#dN

Try it online!

Basically an improvement of this 12 byte answer (please upvote it). To find the maximum value with g# I have used this tip from @isaacg.

Commented:

VQ         # for N in 0..Q-1
  m     Q  #  map over 0..Q-1 (implicit):
    g#dN   #   maximum of mapping variable d and N
   h       #   then add 1

Arturo, 36 33 bytes

$->n->map n'x->map n'y->max@[x,y]

Try it

Husk, 4 bytes

´ṪYḣ

Try it online!

Outputs as a 2d matrix.

´       # argdup: apply a function to two copies of the same argument 
 Ṫ      # Ṫable: make a 'multiplication table' ...
  Y     # ... using function Y = maximum of two values
   ḣ    # with (duplicated) argument ḣ = range from 1 to input number

7 bytes - ¶mw´ṪYḣ - to ouput in the exact same format as the examples in the question.

Perl 5 + -M5.10.0 -na, 37 bytes

$,=$";say+($_)x$_,$_+1.."@F"for 1..$_

Try it online!

JavaScript (Node.js), 52 bytes

n=>(g=(i,j)=>i?[...g(i-1,j),j?i<j?j:i:g(n,i)]:[])(n)

Try it online!


JavaScript (Node.js), 55 bytes

n=>[...Array(n)].map((_,x,a)=>a.map((_,y)=>1+(x+=y>x)))

Try it online!

From user100752(deleted)'s answer

Alternate

RProgN 2, 16 bytes

x=x«y=x²yMS•.p»;

Explaination

x=x«y=x²yMS•.p»;
x=               # Set x to the input
  x«          »; # For 1 - x
    y=           # Assign y to the iterator
      x²  S      # Generate a stack from a pair-function
        yM       # The max of y and the current index
           •.p  # Join via spaces, and print

Try it online!

Vyxal, 2 bytes

ǒ∴

Try it Online!

Wish if we had maximum table....

Wish no more!

Quite literally table by maximum

Perl 5, 39 bytes

//,say map{$",$_<$'?$':$_}@;for@;=1..<>

Try it online!

Uiua, 6 bytes

⊞↥.+1⇡

Try it!

⊞↥.+1⇡
     ⇡  # range
   +1   # increment
  .     # duplicate
⊞↥      # table by maximum

JavaScript (Node.js), 75 bytes

Not the best JS solution for a string output, but really close!

I tried to gain bytes by parsing only a single one-dimensional array, but lost some bytes in calculations, and i don't find how to shorten it further.

n=>[...Array(n*n)].map((_,i)=>Math.max(i%n,i/n|0)+1+(++i%n?' ':`
`)).join``

Try it online!

Thunno 2, 4 bytes

RDȷ§

Try it online!

Explanation

RDȷ§  # Implicit input
R     # Push [1..input]
 D    # Duplicate
  ȷ   # Outer product over:
   §  #  Dyadic maximum
      # Implicit output

Excel (Office 365 Insider Preview), 38 bytes

An anonymous worksheet function that takes input \$n\$ from cell A1 and outputs an \$n\times n\$ dynamic array to the calling cell.

This solution makes use of the =MAKEARRAY() and =LAMBDA() functions, which are currently only available via the Office Insiders program.

=MakeArray(A1,A1,Lambda(r,c,Max(r,c)))

Annotated

=MakeArray(A1,A1,                    ) ' Make an nxn array holding row & col index
                 Lambda(r,c,        )  ' Pass the indices into a function
                            Max(r,c)   ' Take the larger of two at each position
                                       ' Output as nxn dynamic array

Excel VBA, 45 44 bytes

Saved 1 bytes thanks to Taylor Raine because of course. At least now it's my favorite number of bytes.

[A1].Resize([A1],[A1])="=Max(Row(),Column())"

Input is in the cell A1 of the active sheet. Program is run from the immediate window. It works by writing a formula into a range of cells. This will also overwrite the input cell with a formula.

Example5

Example8

Pyth, 12 bytes

VSQm?>dNdNSQ

Try it online!

Pari/GP, 26 bytes

n->matrix(n,,i,j,max(i,j))

Try it online!

Nim, 138 122 bytes

proc x(i:int)=
  for x in 1..i:
    for j in 1..x:stdout.write($x&" ")
    for j in x+1..i:stdout.write($j&" ")
    echo()

ayr, 5 bytes

^:\`~

Explained

    ~  One-range to N
   `   Commute (copy arg to make next symbol dyadic)
  \    Table
^:      Of maxes

Vyxal 2.6.0 r, 4 bytes

ẊvGẇ

Try it Online!

Feels good to have Cartesian product use ranges for numbers now. Posting as a separate answer to emanresuA because it uses features not available in the version they used (haha rewrite go brrr).

Explained

ẊvGẇ
Ẋ    # The Cartesian Product of the ranges [1, input] and [1, input]
 vG  # the maximum of each pair
   ẇ # wrapped to chunks of length input

Rust, 84 bytes

|n|(1..=n).fold("".into(),|a,i|(1..=n).fold(a,|b,j|format!("{}{} ",b,i.max(j)))+"
")

Try it online!

The output will be a String. The newline is given literally inside quotes, which saves one byte.

TI-Basic, 38 41 bytes

Input N
identity(N→[A]
For(I,1,N
For(J,1,N
max(I,J→[A](I,J
End
End
[A]

Output is stored as a matrix in Ans and is displayed.

Python, 52 bytes

lambda a="123456789":[a[n]*n+a[n:]for n in range(9)]

Try it online!

Regenerate, 80 bytes

((${$2+1}|1)( $2){$2-1}( ${$4+1}{1-$4/$~1}| ${$2+1}{1-$2/$~1}){$~1-$2+1}\n){$~1}

Takes the argument from the command-line. Try it here!

Explanation

(Spaces are replaced with underscores to improve visibility.)

Each line is generated in three parts. Top-level structure:

(                           )       Group 1: a line of output
 (...)                               Group 2: the first digit
      (...){...}                     Group 3: repetitions of the first digit
                (...){...}           Group 4: count up to N
                          \n         Add a newline
                             {$~1}  Repeat, generating N lines

Group 2, the first digit on each line:

(         )
 ${$2+1}     Add 1 to the previous value of group 2
        |    Or, if group 2 has not been previously matched...
         1   Use 1

Group 3, the rest of the digits on the line that are identical to the first number:

(_$2)        The most recent value of group 2 (with a space in front of it)
     {$2-1}  repeated (group 2) - 1 times

Group 4, the remaining numbers on the line, starting with (group 2) + 1 and counting up to N:

( ${$4+1}{1-$4/$~1}| ${$2+1}{1-$2/$~1}){$~1-$2+1}
(                                     )
 _                                                 Space
  ${$4+1}                                          Previous value of group 4, plus 1
         {        }                                Repeat the value this many times:
            $4/$~1                                  1 if group 4 == N, 0 otherwise
          1-                                        Subtract from 1: 1 -> 0 and 0 -> 1
                                                   So if the new value would have been N+1,
                                                   it instead becomes empty string
                   |                               If the previous value of group 4 was not
                                                   a number, the arithmetic fails, and we
                                                   instead use...
                    _                              Space
                     ${$2+1}                       Last value of group 2, plus 1
                            {1-$2/$~1}             Repeat 0 times if group 2 == N
                                       {        }  Repeat the above
                                        $~1-$2+1   N - (group 2) + 1 times

Worked example

Suppose the input is 3.

Line 1:

Result: 1 2 3

Line 2:

Result: 2 2 3

Line 3:

Result: 3 3 3

T-SQL (277 bytes)

Not sure how inputs are handled in SQL but my first declared parameter is the input. I also can't get an online T-SQL compiler that runs this. But this will run in your SSMS just fine.

DECLARE @a int = 7DECLARE @ int=1DECLARE @c int=1DECLARE @b nvarchar(max)='SELECT'WHILE @<=@a BEGIN
SET @c=1WHILE @c<=@a BEGIN
SET @b+=IIF(@c=1,'',',')+STR(IIF(@c<@,@,@c))+'AS['+STR(@c)+']'SET @c+=1
END
SET @b+=IIF(@<@a,'UNION ALL SELECT','')SET @+=1
END
EXEC sp_executesql @b;

It's a naive approach with nothing special, except that it dynamically builds up a query.

The query it generates is:

SELECT         1AS[         1],         2AS[         2],         3AS[         3]UNION ALL SELECT         2AS[         1],         2AS[         2],         3AS[         3]UNION ALL SELECT         3AS[         1],         3AS[         2],         3AS[         3]

Python 3, 51 49 bytes

lambda n:mgrid[:n,:n].max(0)+1
from numpy import*

Try it online!

<>^v, 93 89 bytes

i,tTv
v`j1<
>I)iIT‹!0jv
 v        <
 >J)jJI≥v_~ v
        >~  v
 ^  v≤TJ<\23<
    `
^   <
Explanation

i pops the top of the stack (by default 0) and stores it into the variable i. , reads an integer from stdin, then t pops it and stores it into variable t. T pushes to the stack the value of the variable t and v redirects the intruction pointer towards the end of the next line. < tells the instruction pointer to go left. 1 pushes 1 onto the stack and j stores it into the variable j, and ` prints a newline. Then v and > sends the instruction towards the right on the next line. I pushes the variable i's value onto the stack, ) increments it, i takes it and puts it into i, I pushes the value of i onto the stack and T brings onto the stack the number that was previously read to stdin. compares them and terminates the program if the grid has finished printing. Then it initializes j to 0 and sends the instruction pointer into a loop that increments j, then prints a space (\23 (pointer is currently going left, that's why it is reversed) pushes 32 (ASCII id of " ") and prints it) (32\ is used instead of " "~ because it is one character shorter), prints j if j is lower than i, or else prints i. When j is greater or equal to t, it exits the loop, prints a new line and goes back into the outer loop.

In the code, the t variable contains the number read from stdin, i is the current line number, and j is the current character number.

run online

Python 3, 67 bytes

lambda n:[print(*(max(y,x)+1 for y in range(n))) for x in range(n)]

Try it online!

Wolfram Language (Mathematica), 16 bytes

Max~Array~{#,#}&

Try it online!

Haskell, 28 bytes

f n=(<$>[1..n]).max<$>[1..n]

Try it online!

Generates each row by taking the max of each element of [1..n] and a fixed value equal to the row number.

map(max 3)[1,2,3,4,5] = [3,3,3,4,5] 

We use <$> as an infix synonym for map.

It would be nice to reuse the <$>[1..n], but it runs into type-checking issues

26 bytes, doesn't work

f n|q<-(<$>[1..n])=q$q.max

Try it online!

If a 1D output is allowed, we can do:

25 bytes

f n=max<$>[1..n]<*>[1..n]

Try it online!

05AB1E, 6 bytes

Lã€àsä

Try it online! Outputs as a 2D list. Link includes a footer to format the output.

Lã€àsä  # full program
  €     # list of...
   à    # maximum...
  €     # s...
   à    # of...
  €     # each element of...
 ã      # list of distinct combinations of two elements in...
L       # [1, 2, 3, ...,
        # ..., implicit input...
L       # ]...
 ã      # repeated twice...
     ä  # split into pieces of length...
    s   # implicit input
        # implicit output

PHP -F, 80 69 bytes

for(;++$i<=$argn;)echo str_pad('',$i-1,$i).join(range($i,$argn))."
";

Try it online!

Quite naive solution, but I think it can be golfed more..

EDIT: saved 11 bytes by having a shorter str_pad so that the join(range( is no longer conditional

Python 2, 48 bytes

r=range(1,input()+1)
for x in r:print[x]*x+r[x:]

Try it online!

Prints a list for each row.

JavaScript (Node.js), 56 bytes

n=>[...Array(n)].map((_,x,a)=>a.map((_,y)=>x>y++?-~x:y))

Try it online!

Outputs an array of arrays.

Thanks to Shaggy for -5 bytes

Thanks to Arnauld for further -2 bytes

JavaScript (Node.js), 71 bytes

n=>[...Array(n)].map((_,x,a)=>a.map((_,y)=>x>y++?-~x:y).join``).join`
`

Try it online!

Outputs string

History

n=>[...Array(n)].map((_,x,a)=>a.map((_,y)=>-~x>++y?-~x:y)) // 58

n=>[...m=Array(n)].map((_,a)=>[...m].map((_,b)=>-~a>++b?-~a:b)) // 63

n=>[...(m=Array(n))].map((_,a)=>[...m].map((_,b)=>-~a>++b?-~a:b)) // 65

n=>[...(m=Array(n)).keys()].map(a=>[...m.keys()].map(b=>-~a>++b?-~a:b)) // 71

C# (Visual C# Interactive Compiler), 70 bytes

a => new int[a][].Select((x,p)=>new int[a].Select((y,q)=>p>q?p+1:q+1))

I'm sure there is a shorter way to do this, but I can't find it.

Try it online!

Java (JDK), 84 bytes

n->{for(int i=0;i<n*n;)System.out.printf("%d%c",i%n>i/n?i%n+1:i/n+1,++i%n<1?13:32);}

Try it online!

Alternative, 84 bytes too

n->{for(int i=1,j=0;i<=n;)System.out.printf("%d%c",i>++j?i:j,(j%=n)<1?13+i-i++:32);}

Try it online!

Japt, 5 bytes

Outputs a 2D-array.

õ@õwX

Try it

õ@õwX     :Implicit input of integer U
õ         :Range [1,U]
 @        :Map each X
  õ       :  Range [1,U]
   wX     :  Max of each with X

Or, if outputting a 1D-array is allowed:

Japt, 4 bytes

õ ïw

Try it

õ ïw     :Implicit input of integer U
õ        :Range [1,U]
  ï      :Cartesian product with itself
   w     :Reduce each pair by Max

Ruby, 35 bytes

->x{(1..x).map{|y|[y]*y+[*y+1..x]}}

Try it online!

Vyxal, 6 bytes

ƛ£⁰ƛ¥∴

Try it Online! Returns an array of arrays

ƛ      # (1...input) Map...
 £     # Push to register
  ⁰ƛ   # (1...input) Map...
    ¥  # Register
     ∴ # Maximum of the two

Or, for grid output, 10 bytes:

ƛ£⁰ƛ¥∴;Ṅ;⁋

Try it Online!

ƛ       ;  # (1...input) Map...
 £         # Push to register
  ⁰ƛ  ;    # (1...input) Map...
    ¥      # Push register
     ∴     # Max
       Ṅ   # Joined by spaces
         ⁋ # Joined by newlines.

Python 3, 49 bytes

f=lambda x:x*[x]and[a+[x]for a in f(x-1)]+[[x]*x]

Try it online!

PowerShell Core, 40 bytes

param($a)1..$a|%{"$(,$_*($_-1)+$_..$a)"}

Try it online!

Factor, 35 bytes

[ [1,b] dup [ max ] cartesian-map ]

Try it online!

cartesian-map Takes two sequences (in this case, both are [1, n]) and applies a quotation to each pair of elements, resulting in a matrix. In effect, we are mapping max over a coordinate matrix.

Stax, 3 bytes

╗ìΦ

Run and debug it

Octave, 19 bytes

@(n)max([1:n]',1:n)

Try it online!

R, 30 bytes

function(n)outer(1:n,1:n,pmax)

Try it online!

C (gcc), 65 bytes

i,j;f(n){for(i=1;n/i;)printf(j/n?j=!++i,"%d\n":"%d ",i>++j?i:j);}

Try it online!

Charcoal, 11 bytes

NθEθ⭆θ⊕⌈⟦ιλ

Try it online! Link is to verbose version of code. Explanation:

Nθ          First input as an integer
   θ        Input
  E         Map over implicit range (0-indexed)
     θ      Input
    ⭆       Map over implicit range and join
         ι  Outer index
          λ Inner index
       ⌈⟦   Maximum of all of the above
      ⊕     Incremented
            Implicitly print

Would be 14 bytes if spacing was desired (13 bytes if a leading space was acceptable).

C (clang), 75 77 bytes

Added 2 bytes for a bug fix kindly provided by dingledooper.

i;j;k;f(n){for(i=0;n/++i;puts(""))for(j=i,k=0;n/++k;j+=k>=i)printf("%d ",j);}

Try it online!

K (ngn/k), 10 bytes

{x|\x}1+!:

Try it online!

Somewhat surprisingly, using a seeded scan x|\x returns the same results as an each-right (x|/:x) or each-left (x|\:x).

Julia, 19 bytes

!n=max.((1:n)',1:n)

Try it online!

Posix SH + sed, 99 97 96 bytes

seq -s\  $1|sed -nE ':t
p
s/((.)( \2)*) (.)/\1=\4/
/(.)=\1/q
:r
s/ ?(.)=(.)/=\2 \2/
tr
s/=//
tt'

or, 99 bytes with looping (ugh):

seq -s\  $1|sed -nE ':t
p
s/(.) /\1=/
:l
s/(.)=\1 ?/\1 \1=/
tl
:r
s/ ?(.)=(.)/=\2 \2/
tr
s/^=//
tt'

With an earlier gnu sed version, :t and tt can be replaced with : and t, respectively, saving two bytes for each solution (I think).

Takes input in $1. Outputs exactly as in the question (but with a trailing newline I think).

Explanation

seq -s\  $1       \  # Collect the numbers 1..$1 with space as
                  \  # the -separator.
  |sed -nE '...'     # Replace it. The -E is for -Extended Regular
                     # Expressions, which allow less escaping.
                     # The -n is for -no printing by default.
:t                          # Label for "t"op.
p                           # "p"rint the line.
s/((.)( \2)*) (.)/\1=\4/    # Mark the end of the first run of
                            # equal elements followed by a number.
                            #    4 4 4 4 5 6 7 8 9
                            # => 4 4 4 4=5 6 7 8 9
                            #    9 9 9 9 9 9 9 9 9
                            # => 9 9 9 9 9 9 9 9=9
/(.)=\1/q                   # If the marked element and its successor
                            # are the same (like in the example above
                            # with all nines), "q"uit, don't process
                            # any more lines.
:r                          # Start "r"eplacement loop.
s/ ?(.)=(.)/=\2 \2/         # For any characters a, b, replace a=b
                            # with =b b. examples:
                            #    4 4 4 4=5 6 7 8 9
                            # => 4 4 4=5 5 6 7 8 9
                            # => 4 4=5 5 5 6 7 8 9
tr                          # "t"est if there was a replacement made.
                            # if there was, do another replacement
                            # loop iteration.
s/=//                       # At this point, the cursor must have
                            # reached the beginning of the line
                            # so no replacement could be made.
                            # Remove the =
tt                          # Go to the top again, where this row
                            # will be printed, and a new one will be
                            # started.

Vyxal, 15 bytes

ɾƛnS:I*fvI⁰ɾnȯJ

Try it Online!

Wish if we had maximum table....

JavaScript (Node.js), 85 bytes

n=>[...(A=Array)(n)].map((_,i)=>[...A(i++).fill(i),...[...A(n-i+1)].map((u,j)=>i+j)])

Try it online!

In the form of an array. Since JS doesn't have the convenient list.__mul__ and list.__add__ operations, this takes up quite some space.


JavaScript (Node.js), 90 bytes

f=(n,i=0)=>n-i?`${i+1} `.repeat(i)+[...Array(n-i++)].map((_,j)=>i+j).join` `+`
`+f(n,i):''

Try it online!

As a string.


Python 2, 50 bytes

lambda x:[[i+1]*i+range(i+1,x+1)for i in range(x)]

Try it online!

-2 bytes thanks to dingledooper

J, 9 bytes

1+>./~@i.

Try it online!

Explanation

1+>./~@i.    input: n
       i.    range from 0 to n-1 inclusive
    /~       table:
  >.            max(n, n)
1+           add 1 to each

APL (Dyalog Unicode), 11 bytes

{(⍳⍵)∘.⌈⍳⍵}

Anonymous prefix function

-2 bytes thanks to @Adam in chat

APL (Dyalog Unicode), 5 bytes (SBCS)

Anonymous tacit prefix function.

∘.⌈⍨⍳

Try it online!

∘.⌈⍨ maximum-table for

integers 1 through the argument

Jelly, 2 bytes

»þ

Try it online!

Outputs an n x n matrix. If the output format is required, 4 bytes

This is simply a table of maximums. For each cell \$A_{i,j}\$ in the output, the result is equal to \$\max(i,j)\$. The 4 byte answer has ` to reuse the argument, and G to format the output as a grid.