g | x | w | all
Bytes Lang Time Link
024Uiua 0.15.0dev.1250107T194909ZTbw
01005AB1E250113T120747ZKevin Cr
008Jelly250106T220540ZJonathan
027K ngn/k250110T115955Zatt
071R250107T115840Zpajonk
050Charcoal250105T201301ZNeil
111Maple250105T033743Zdharr
066JavaScript Node.js250103T072536Ztsh
081JavaScript Node.js250103T063604Zl4m2

Uiua 0.15.0-dev.1, 24 bytes SBCS

⍥(⊂⊂⤚-+1°⊂⊃↙↘⧻⊚=⊢..):-1⊚

Try on Uiua Pad!

Thought I might as well give my own solution since I don't think anyone else is using this method.

Takes \$n\$ and \$S\$ and returns an array of the Pascal-ary representation on the stack by incrementing the representation \$S\$ times.

⍥(⊂⊂⤚-+1°⊂⊃↙↘⧻⊚=⊢..):-1⊚
                       ⊚ # array of n zeros
                     -1  # minus 1, array of n -ones
⍥(                 ):    # do the following S times...
                 ..      # dup array twice on stack
                ⊢        # first element (k)
               =         # test equality
             ⧻⊚         # number of 1s
             ⧻⊚=⊢..     # length of first run of k
          ⊃↙↘            # split at that index
        °⊂               # pop the first k off the array
      +1                 # add 1
    ⤚-                   # subtract from the array, leaving k+1 below
   ⊂                     # append
   ⊂⤚-+1°⊂              # turn [k k ... k k] to [-1 -1 ... -1 k+1]
  ⊂                      # rejoin the rest of the array

I also found four other solutions with 24 characters and under factored out to varying degrees for people that like that kind of thing (or those that want to golf this more).

⍥(⍜↙(⊂⤚-+1°⊂)/+=⊢..):-1⊚
⍥(⍜↙⍜°⊂(⤚-+1)/+=⊢..):-1⊚
⍥(⍜⊕□⍜⊢⍚(⊂⤚-+1°⊂)⊛.):-1⊚
⍥(⍜⊕□⍜⊢⍚⍜°⊂(⤚-+1)⊛.):-1⊚

05AB1E, 10 bytes

®ŸIã€{Ù¹±è

Port of @JonathanAllan's Jelly answer, so make sure to upvote that answer as well!
(Jelly's œċ builtin is basically Iã€{Ù in my ported answer, and instead of negating \$S\$ to \$-S\$, I use the bitwise-NOT to make it \$-S-1\$, since Jelly uses 1-based indexing (with index 0 being the rightmost item) and 05AB1E uses 0-based indexing (with index -1 being the rightmost item).)

Inputs in the order \$S,N\$.

Try it online or verify (almost) all test cases (the last test case is omitted, since it times out).

Explanation:

®Ÿ         # Push a list in the range [(implicit) input S, -1]
  Iã       # Get all N-sized lists using these values with the cartesian product
    €{     # Sort each inner list from lowest to highest
      Ù    # Uniquify this list of lists
       ¹   # Push the first input S again
        ±  # Bitwise-NOT it: -S-1
         è # Use that to modular 0-based index into the list of lists
           # (where -1 takes the rightmost list; -2 the one preceding it; etc.)
           # (which is output implicitly as result)

Jelly, 8 bytes

Nịr-œċUʋ

A dyadic Link that accepts the Sum, \$S\$, on the left and the Length, \$N\$, on the right and yields the Pascal-ary representation as a list of integers.

Try it online! (too inefficient to do \$S=10000, N=7\$.)

How?

Nịr-œċUʋ - Link: integer, S; integer, N
N        - negate {S} -> -S
       ʋ - last four links as a dyad - f(S, N):
   -     -   literal -1
  r      -   {S} inclusive range {-1} -> [S,S-1,S-2,...,1,0,-1]
    œċ   -   combinations with replacement, choosing {N} elements from {that}
      U  -   reverse each of {those} -> Candidates
 ị       - {-S} index into {Candidates}
           (0 gets the rightmost, -1 the next rightmost, ...)

K (ngn/k), 27 bytes

{-1+y{(|\a)*x+a:~><>x}/x#0}

Try it online!

Input [n;S]. Generates the Sth valid output.

                      x#0   start with n 0s
   y{               }/      S times:
           x+  ~><>x          increment last place of min
     (|\a)*                   zero lower places
-1+                         decrement

K (ngn/k), 25 bytes

{-1+('[|/<':]_+|!x#y+2)y}

Try it online!

Brute force. Don't even think about trying the last test case.

R, 71 bytes

`?`=\(n,S,r=S:-1,q=choose)if(n>0)c(a<-r[q(r+n,r)<=S][1],n-1?S-q(a+n,a))

Attempt This Online!

Greedy algorithm. Outputs the sequence in reverse order.

Charcoal, 50 bytes

NθF⮌…·¹N«≔⟦¹⟧εW¬›⌈εθ⊞ε÷×⌈ε⁺ιLεLε⊞υ∧⊟ε⊖Lε≧⁻↨ε⁰θ»I⮌υ

Try it online! Link is to verbose version of code. Takes inputs in the order S, n. Explanation: Uses the greedy algorithm.

Nθ

Input S.

F⮌…·¹N«

Input n and count i down from N until 1.

≔⟦¹⟧ε

Start computing binomial coefficients with aᵢ=0.

W¬›⌈εθ

Until the binomial exceeds S...

⊞ε÷×⌈ε⁺ιLεLε

... compute the next binomial in the ith diagonal.

⊞υ∧⊟ε⊖Lε

Remove the binomial that was too large and save the resulting aᵢ.

≧⁻↨ε⁰θ

Subtract the appropriate coefficient from S.

»I⮌υ

Output the aᵢs in ascending order of i.

Maple, 111 bytes

proc(n,S)t:=();s:=S;B:=0;for i to n do b:=1;for m while b<=s do B:=b;b*=(n+1-i+m)/m od;t:=m-2,t;s-=B od;[t]end;
proc(n,S)
  t:=();                # initialize output sequence to NULL
  s:=S;                 # copy of S to modify
  B:=0;                 # kludge for case n>1, S=0 so "while" test is OK
  for i to n do         # for each output working backwards (i=1 for last output)
    b:=1;               # initialize Pascal diagonal
    for m while b<=s do # m counts along diagonal (but offset by 2)
      B:=b;             # save b for when we exceed s
      b*=(n+1-i+m)/m    # update diagonal
    od;
    t:=m-2,t;           # save how far along diagonal, put before previous values
    s-=B                # decrease sum for next (earlier) output
  od;
  [t]                   # return list
end;

Just a rather inelegant version of the greedy algorithm.

JavaScript (Node.js), 66 bytes

-2 bytes by Arnauld

n=>g=(S,v,i=1,u=v-v*n/--i||1)=>u<=S?g(S,u,i):[...--n?g(S-v):[],~i]

Try it online!

A simple greedy solution. I have no idea why greedy algorithm works, but whatever, it passas all testcases.

JavaScript (Node.js), 81 bytes

n=>g=(S,x=Array(n).fill(-1))=>S?g(S-1,x.map(t=(c,j)=>1/t?c:c>=x[j+1]?-1:t=c+1)):x

Try it online!

Hint says that there is only one valid output for any input. so the n-th largest valid output is answer