[Question]
  [
*Related: [Let's design a digit mosaic](https://codegolf.stackexchange.com/questions/167337/lets-design-a-digit-mosaic), [Print/Output the L-phabet](https://codegolf.stackexchange.com/questions/87064/print-output-the-l-phabet). [Sandbox post here](https://codegolf.meta.stackexchange.com/a/16667/78039)*
Given 2 inputs `C = columns and rows, S = starting point` output a matrix as follow:
```
Input 4, 3
1   2   3   0
2   2   3   0
3   3   3   0
0   0   0   0
```
**Explanation**
**Given** `C = 4, S = 3`
1) Create a `C x C` matrix filled with `0`
```
         4 columns
4     _____|____
     |          |
r  --0  0   0   0
o |  0  0   0   0
w |  0  0   0   0
s  --0  0   0   0
```
2) Fill with `S` values within row and column `S`, then subtract 1 from `S` and repeat until `S = 0`. This case `S = 3`
```
             Column 3 
S = 3           |
                v
        0   0   3   0
        0   0   3   0
Row 3-->3   3   3   0
        0   0   0   0
         Column 2
S = 2       |
            v
        0   2   3   0
Row 2-->2   2   3   0
        3   3   3   0
        0   0   0   0
     Column 1
S=1     |
        v
Row 1-->1   2   3   0
        2   2   3   0
        3   3   3   0
        0   0   0   0
Final Result
1   2   3   0
2   2   3   0
3   3   3   0
0   0   0   0
```
---
**Rules**
* Assume `C >= S >= 0`
* The output can be a matrix, list of lists, array (1-dimensional or 2-dimensional) etc.
* You can take inputs via any [default I/O format](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods)
* Your program, function, etc... may be 1-indexing or 0-indexing. Please specify which one is.
**Note** Explanation is 1-indexing
---
Winning criteria [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'")
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 [bytes](https://github.com/DennisMitchell/jellylanguage/wiki/Code-page)
```
»>⁴¬×»µþ
```
[Try it online!](https://tio.run/##ASAA3/9qZWxsef//wrs@4oG0wqzDl8K7wrXDvv/Dp0f//zT/Mw "Jelly – Try It Online")
## How it works
**Jelly's Outer Product Atom (`þ`)**
You can think of Jelly's outer product atom, `þ`, as a quick (operator) that, given integer arguments \$X\$ and \$Y\$ (in this case \$X=Y=\text{first argument }\$), produces the following matrix of tuples:
$$\left[\begin{matrix}
(1, 1) & (2, 1) & (3, 1) & \cdots & (X, 1) \\
(1, 2) & (2, 2) & (3, 2) & \cdots & (X, 2) \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
(1, Y) & (2, Y) & (3, Y) & \cdots & (X, Y)
\end{matrix}\right]$$
It also applies the link right before it to all pairs, let's call it \$\:f\$, which behaves like a function which takes two arguments, producing something like this:
$$\left[\begin{matrix}
f(1, 1) & f(2, 1) & f(3, 1) & \cdots & f(X, 1) \\
f(1, 2) & f(2, 2) & f(3, 2) & \cdots & f(X, 2) \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
f(1, Y) & f(2, Y) & f(3, Y) & \cdots & f(X, Y)
\end{matrix}\right]$$
**How is it relevant to the task at hand?**
This works by noticing that every value in the expected output is just a table of maximal indices, or \$0\$ if this maximum exceeds our second argument. Therefore, we can create the following link to perform this mapping:
```
»>⁴¬×» – Dyadic (2-argument) link.
»      – Maximum of the X, Y coordinates.
 >⁴    – Check if this exceeds the second argument of the program.
   ¬   – Negate this boolean.
    ×» – And multiply by the maximum, computed again.
```
[Answer]
# [R](https://www.r-project.org/),  ~~47~~ 41 bytes
```
function(C,S,m=outer(1:C,1:C,pmax))m*!m>S
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP0/DWSdYJ9c2v7QktUjD0MpZB4QLchMrNDVztRRz7YL/p2mY6BhrcoEoA83/AA "R – Try It Online")
1-indexed. Generates the outputs for `S==C` (no zeros) then zeroes cells which have a value `>S` using matrix multiplication (thanks Giuseppe for 4 bytes!).
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 31 bytes
```
@(C,S)(u=max(t=1:C,t')).*(u<=S)
```
Anonymous function that returns a matrix. Uses 1-based indexing.
[Try it online!](https://tio.run/##y08uSSxL/Z9mq6en999Bw1knWFOj1DY3sUKjxNbQylmnRF1TU09Lo9TGNljzf5qGiY6x5n8A "Octave – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), ~~47~~ 45 bytes
-2 bytes by changing the output format to one-dimensional list.
```
c&s|x<-[1..c]=[sum[j|j<=s]|j<-x>>=(<$>x).max]
```
[Try it online!](https://tio.run/##VZBBS8NAFITv/oqhlJJAExB7kiQgepJ60YOHNMiS3dptN2@X3beYQv973EoUvLzDzHzM8A4inJQxkx6c9YwnwaLc6sDIEGlvjfTIURSwZM4gpaSS2FsP5xXzGTayizz1q3AZq6K9Lcu@q9sQh/Z4OVZ16NItxqaps2rZjHk5iLGbBqEJNaS9Adp@HTpUBQbh4JWQKPFlvQxIAD4VP1piRRxS1ihOkRANJ7rHClcx1b@x3xIWaeXrj3u/o8XV8Zp@gX/BHaVob32ynKVUxXZG0oiXjxnMWJzU@0EbhYwsp10Ujcmx/HtM9hzDVQ/OaH5gbPK5LZ82uPsG "Haskell – Try It Online")
## Explanation
The term `x >>= (<$> x) . max` is a golfed version of
```
concat [ max i <$> x | i <- x ]
```
which evaluates to `[1,2,3,4..c, 2,2,3,4..c, 3,3,3,4..c, ..., c,c,c,c..c]`. Now we only need to force the values to `0` once they exceed `s` which we achieve with `sum [ j | j <= s]`.
[Answer]
**APL(Dyalog Classic), 12 bytes**
```
{⍺ ⍺↑∘.⌈⍨⍳⍵}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v8/7VHbhOpHvbsUgPhR28RHHTP0HvV0POpd8ah386PerbX//5sopCkYc6mrc5kBGSYA)
Any tips on turning this into a train are welocome.
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 12 bytes
```
o×⎕≥o←∘.⌈⍨⍳⎕
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qKNdIe1//uHpj/qmPupcmv@obcKjjhl6j3o6HvWueNS7GSgMUvM/jcuEyxgA "APL (Dyalog Unicode) – Try It Online")
[Answer]
# JavaScript (ES6), 61 bytes
Takes input in currying syntax `(c)(s)`, where *s* is 1-indexed. Returns a 1-dimensional array.
```
c=>s=>[...Array(c*c)].map((_,k)=>(k=k%c>k/c?k%c:k/c)<s?-~k:0)
```
[Try it online!](https://tio.run/##Fcy9DoIwFEDhnafooOm9UqqJTsSWOPgCrmKEXH6EIiWUGA3BV0ecvjOdOn2ljvqqG4LWZvlcqJmUdkpfpZSnvk8/QBvCm3ymHcBdGFQajDJr0mZL0WK4iEcXBV8T7nAecjcwxYAEc8iUZlAAISztM85x@Qz0gEtent8dJBDHmS8iHFcjTVMiGC85oqxt1QKPW46eR7Z1tsllY0v4z@Eg2B5x/gE "JavaScript (Node.js) – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
⁴Ri»µþ
```
A full program\* taking integers `C` and `S` which prints the Jelly representation of a list of lists of integers as defined (1-indexed).
**[Try it online!](https://tio.run/##AR0A4v9qZWxsef//4oG0UmnCu8K1w77/w6dH//8xNv8xMQ "Jelly – Try It Online")** (formats the result of the dyad as a grid of numbers for easier reading)
### How?
```
⁴Ri»µþ - Main Link: C, S
     þ - outer product with:
    µ  -   the monadic function (i.e. f(x,y) for x in [1..C] for y in [1..C]):
   »   -     maximum (of x and y)
⁴      -     program's 4th argument = 2nd input = S
 R     -     range = [1,2,3,...S]
  i    -     first index of (the maximum) in (the range) or 0 if not found
       - as a full program: implicit print
```
---
\* The reason this is a full program is down to the use of the program argument access, `⁴`. As a dyadic link this code would rely on how the program which is using it is called.  
Reusable dyadic link in 8 bytes (taking S on the left and C on the right): [`RiⱮⱮ»þ`}`](https://tio.run/##y0rNyan8/z8o89HGdUB0aPfhfQm1/w8vd///39Dwv6EZAA "Jelly – Try It Online")  
Reusable dyadic link in 8 bytes (taking C on the left and S on the right): [`RiⱮⱮ⁹»þ¤`](https://tio.run/##y0rNyan8/z8o89HGdSDUuPPQ7sP7Di35f3i5@///hob/Dc0A "Jelly – Try It Online")
[Answer]
# Java 10, 88 bytes
```
C->S->{var r=new int[C][C];for(;S>0;)for(int s=S--;s-->0;)r[S][s]=r[s][S]=S+1;return r;}
```
[Try it online.](https://tio.run/##jZFBS8QwEIXv/oo5tmjCFhXB2IIsCB4EIcfSQ@y2S2o3Lcm0Wpb@9jrdprgHFSGEx8yb8L1JpXrFqt37lNfKOXhR2hwvABwq1DlU1OUd6pqXnclRN4Y/efHwbLDYF/bqfyZtMM3SLEmghHjaskSy5NgrCzY2xcepvc3oiLKxgZDJRoSzojq4WDImHGNz0aYyS10WW7pIxvIyErbAzhqwYpwEsdNpu7ea8H2KvtE7OFCyQKLVZp9moMI5JRlpFodXqmJQctW29RDchl5ch6H41XWzuqK/XNFmtd0ttnEBPCc7n/NrIloi/fSQfhEzNtyvrVMHQA4OiwNvOuTt/EJtgu//eLRWDY5js@QO1Ir6w5SnG6cv)
**Explanation:**
```
C->S->{                     // Method with two int parameters and int-matrix return-type
  var r=new int[C][C];      //  Result-matrix of size `C` by `C`
  for(;S>0;)                //  Loop as long as `S` is not 0 yet:
    for(int s=S--;s-->0;)   //   Inner loop `s` in the range (`S`, 0]
                            //   (and decrease `S` by 1 in the process with `S--`)
      r[S][s]=r[s][S]=S+1;  //    Set the values at both {`S`,`s`} and {`s`,`S`} to `S+1`
  return r;}                //  Return the result
```
[Answer]
# [PHP](http://www.php.net/), 92 bytes
This is "1-indexing".
```
<?list(,$c,$s)=$argv;for(;$i++<$c;print"\n")for($j=0;$j++<$c;)echo$s<$i||$s<$j?0:max($i,$j);
```
To run it:
```
php -n <filename> <c> <s>
```
Example:
```
php -n collapsing_matrice.php 8 6
```
Or [Try it online!](https://tio.run/##JclBCoMwEEbhu8i/SDAFV0WciBdxI6GtE9okJEFceHZHpKsH30trErHTl0tVBs6g6BFL/mz0jlkRuG0tHKXMoTZzaPTN8GNH8P@lX26NKBZ8HHf81A2/ZVdgA69JRHp5njFVjqHII1w "PHP – Try It Online")
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 10 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
▓╜.→,cΘ○╤æ
```
[Run and debug it](https://staxlang.xyz/#p=b2bd2e1a2c63e909d191&i=4,+3%0A6,+0%0A0,+0%0A2,+2&a=1&m=2)
How it works:
```
R(Xm]i*xit+J Full program, implicit input.
R            1-based range of S
 (           Right-pad with zeroes to length C
  X          Save to X register
   m         Map (same as [here](https://codegolf.stackexchange.com/a/167360)):
    ]          Wrap in list
     i*        repeat by iteration index
       xit     Remove first  elements from X register
          +    Append
           J   Stringify each element, and join by space
```
[Answer]
# Excel VBA, 65 bytes
An immediate window function that takes input from `[A1:B1]` and outputs to the range `[C1].Resize([A1],[A1])`.
```
[C1].Resize([A1],[A1])=0:For s=-[B1]To-1:[C1].Resize(-s,-s)=-s:Next
```
### Input / Output
Input is in range `[A1:B1]`
[![I/O](https://i.stack.imgur.com/8eC5y.png)](https://i.stack.imgur.com/8eC5y.png)
[Answer]
# [J](http://jsoftware.com/), 18 bytes
```
,~@[{.[:>./~1+i.@]
```
Much longer than both APL solutions.
[Try it online!](https://tio.run/##y/qfVmyrp2CgYKVg8F@nziG6Wi/ayk5Pv85QO1PPIfa/JpeSnoJ6mq2euoKOQq2VQloxF1dqcka@golCmoIxhGkGZJr8BwA "J – Try It Online")
[Answer]
# MATLAB, 58 bytes (Thanks to anonymous user)
```
function o=f(c,s);o=zeros(c);for j=s:-1:1;o(1:j,1:j)=j;end
```
Just filling the elements of matrix with appropriate number, running a loop. Maybe possible to be cleverer with `arrayfun`
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 85 bytes
```
c=>s=>{var r=new int[c,c];for(;s>0;)for(int j=s--;j-->0;)r[s,j]=r[j,s]=s+1;return r;}
```
[Try it online!](https://tio.run/##dVCxasMwEN39FUfoIGM7JEOhVJGXlk4tFDp0MB6MIgcJW4I7JSUYf7sr22niUvqG0/HuvdOTJGXSoRpkUxHBe9RFEEC@8loCqmrvbHOGjzN51a5fjlbutPXpXyKUIi3zHGoQ0SBFTiLvThUCCqu@prFMZclrh4xTvuHx2AUajKAs4ybLRhILSk0psDAplYKSLUflj2gBeT/ABTxahjw5vYe3SltGHrU9FCVUeKB40szPGTFmkSDggf@i2kDVTMbsPr4NQjSYsukw3aRgeOh2IMORJPFVdlt@NZnRwMHMarNU/@DydU/OkmvU@hO1V@xu1bWFDjeVj8/bHmC1SPOf6VVbxRa6PpprP3wD "C# (.NET Core) – Try It Online")
A port of [Kevin Cruijssen's answer](https://codegolf.stackexchange.com/a/168879/70347), which was much better than mine.
[Answer]
# [Python 2](https://docs.python.org/2/), 58 bytes
```
lambda C,S:[-~max(i%C,i/C)*(i%C<S>i/C)for i in range(C*C)]
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUcFZJ9gqWrcuN7FCI1PVWSdT31lTC8SyCbYDsdPyixQyFTLzFIoS89JTNZy1nDVj/6ekpim4aQB1alpxcToq2CqkgTlcnAVFmXklICNhTEcuTnQTNK2gUtGZWs5WQKztHMvF5aZhomOsyfUfAA "Python 2 – Try It Online")
Outputs a 1D list of length `C*C`.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 19 bytes
```
Ｅθ⪫ＩＥＥθ⌈⟦ιλ⟧∧‹λη⊕λ 
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM3sUCjUEfBKz8zT8M5sRgiABX0TazIzC3N1YjO1FHIidXU1FFwzEvR8EktLtbI0VHIAPI985KLUnNT80pSUzRyNDVBSpQUlIC09f//0SY6Csax/3XLcgA "Charcoal – Try It Online") Link is to verbose version of code. 3 bytes used to convert the output to decimal and format it nicely. Explanation:
```
 θ                  Input `C`
Ｅ                   Map over implicit range
      θ             Input `C`
     Ｅ              Map over implicit range
          λ         Inner index
         ι          Outer index
       ⌈⟦  ⟧        Maximium
    Ｅ               Map over results
              λ     Current value
               η    Input `S`
             ‹      Less than
                 λ  Current value
                ⊕   Incremented
            ∧       Logical AND
   Ｉ                Cast to string
  ⪫                 Join with spaces
                    Implicitly print on separate lines
```
[Answer]
# [Clean](https://github.com/Ourous/curated-clean-linux), 67 bytes
```
import StdEnv
$n s=[[if(i>s||j>s)0(max i j)\\i<-[1..n]]\\j<-[1..n]]
```
[Try it online!](https://tio.run/##S85JTcz7n5ufUpqTqpCbmJn3PzO3IL@oRCG4JMU1r4xLJU@h2DY6OjNNI9OuuKYmy65Y00AjN7FCIVMhSzMmJtNGN9pQTy8vNjYmJgvO/h9ckgg0wlZBRcFEwej/v@S0nMT04v@6nj7/XSrzEnMzk4sB "Clean – Try It Online")
Defines `$ :: Int Int -> [[Int]]` giving an answer using 1-based indexing.
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 37 bytes
```
{((^$^c+1 Xmax^$c+1)Xmin$^s+1)X%$s+1}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/WkMjTiUuWdtQISI3sSJOBcjSjMjNzFOJKwaxVFWAVO3/4sRKhTQNvWiDWB0FvWjDWE29ovyS/CKwiKZeVn5mnoZSTJ6Spo4CiFJIyy/i0jDRUTDW1OHSMDTSUTDXtP4PAA "Perl 6 – Try It Online")
Returns the matrix as 1-dimensional array.
[Answer]
# Mathematica 44 bytes
```
Table[If[i <= s && j <= s, Max[i, j], 0], {i, c}, {j, c}]
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 11 bytes
```
T0:´ṪYḣ⁰`R0
```
[Try it online!](https://tio.run/##AR4A4f9odXNr//9UMDrCtOG5qlnhuKPigbBgUjD///8z/zQ "Husk – Try It Online") The function takes `S` followed by `C`.
]