Skip to main content
typo
Source Link
Arnauld
  • 205.4k
  • 21
  • 186
  • 670
a =>                 // a[] = coefficients in ascending order
a.map((_, k) =>      // for each coefficient at index k in a[]:
  a.reduce(          //   for each coefficient v at index n in a[],
    (t, v, n) =>     //   with t as the accumulator:
    t +              //     add to t ...
    v * (            //     ... v multiplied by S(n, k)
                     //     actually implemented as s(n) where s is ...
      s = n =>       //     ... a recursive function taking only n explicitly:
      n ?            //       if n is not 0:
        s(--n, k--)  //         compute S(n - 1, k - 1)
        + ++k * s(n) //         + k * S(n - 1, k)
      :              //       else:
        !k           //         return 1 if k = 0, or 0 otherwise
    )(n),            //     initial call to Ss
    0                //     start with t = 0
  )                  //   end of reduce()
)                    // end of map()
a =>                 // a[] = coefficients in ascending order
a.map((_, k) =>      // for each coefficient at index k in a[]:
  a.reduce(          //   for each coefficient v at index n in a[],
    (t, v, n) =>     //   with t as the accumulator:
    t +              //     add to t ...
    v * (            //     ... v multiplied by S(n, k)
                     //     actually implemented as s(n) where s is ...
      s = n =>       //     ... a recursive function taking only n explicitly:
      n ?            //       if n is not 0:
        s(--n, k--)  //         compute S(n - 1, k - 1)
        + ++k * s(n) //         + k * S(n - 1, k)
      :              //       else:
        !k           //         return 1 if k = 0, or 0 otherwise
    )(n),            //     initial call to S
    0                //     start with t = 0
  )                  //   end of reduce()
)                    // end of map()
a =>                 // a[] = coefficients in ascending order
a.map((_, k) =>      // for each coefficient at index k in a[]:
  a.reduce(          //   for each coefficient v at index n in a[],
    (t, v, n) =>     //   with t as the accumulator:
    t +              //     add to t ...
    v * (            //     ... v multiplied by S(n, k)
                     //     actually implemented as s(n) where s is ...
      s = n =>       //     ... a recursive function taking only n explicitly:
      n ?            //       if n is not 0:
        s(--n, k--)  //         compute S(n - 1, k - 1)
        + ++k * s(n) //         + k * S(n - 1, k)
      :              //       else:
        !k           //         return 1 if k = 0, or 0 otherwise
    )(n),            //     initial call to s
    0                //     start with t = 0
  )                  //   end of reduce()
)                    // end of map()
saved 1 byte
Source Link
Arnauld
  • 205.4k
  • 21
  • 186
  • 670

JavaScript (ES6), 7877 bytes

a=>a.map((_,k)=>a.reduce((t,v,n)=>t+v*(S=k=>ns=n=>n?s(--n+k*S(n,k--)+S+ ++k*s(k-1n)-n++:!k)(kn),0))

Try it online!Try it online!

a =>                 // a[] = coefficients in ascending order
a.map((_, k) =>      // for each coefficient at index k in a[]:
  a.reduce(          //   for each coefficient v at index n in a[],
    (t, v, n) =>     //   with t as the accumulator:
    t +              //     add to t ...
    v * (            //     ... v multiplied by S(n, k)
                     //     actually implemented as Ss(kn) where Ss is ...
      Ss = kn =>       //     ... a recursive function taking only kn explicitly:
      n ?            //       if n is not 0:
        s(--n        //         decrement n
        +, k * S(k--)  //         compute k * S(k)
        + S(kn - 1) //         +, S(k - 1)
        - n++  + ++k * s(n) //         restore n+ (andk cancel* outS(n the- earlier1, --nk)
      :              //       else:
        !k           //         return 1 if k = 0, or 0 otherwise
    )(kn),            //     initial call to S
    0                //     start with t = 0
  )                  //   end of reduce()
)                    // end of map()

JavaScript (ES6), 78 bytes

a=>a.map((_,k)=>a.reduce((t,v,n)=>t+v*(S=k=>n?--n+k*S(k)+S(k-1)-n++:!k)(k),0))

Try it online!

a =>               // a[] = coefficients in ascending order
a.map((_, k) =>    // for each coefficient at index k in a[]:
  a.reduce(        //   for each coefficient v at index n in a[],
    (t, v, n) =>   //   with t as the accumulator:
    t +            //     add to t ...
    v * (          //     ... v multiplied by S(n, k)
                   //     actually implemented as S(k) where S is ...
      S = k =>     //     ... a recursive function taking only k explicitly:
      n ?          //       if n is not 0:
        --n        //         decrement n
        + k * S(k) //         compute k * S(k)
        + S(k - 1) //         + S(k - 1)
        - n++      //         restore n (and cancel out the earlier --n)
      :            //       else:
        !k         //         return 1 if k = 0, or 0 otherwise
    )(k),          //     initial call to S
    0              //     start with t = 0
  )                //   end of reduce()
)                  // end of map()

JavaScript (ES6), 77 bytes

a=>a.map((_,k)=>a.reduce((t,v,n)=>t+v*(s=n=>n?s(--n,k--)+ ++k*s(n):!k)(n),0))

Try it online!

a =>                 // a[] = coefficients in ascending order
a.map((_, k) =>      // for each coefficient at index k in a[]:
  a.reduce(          //   for each coefficient v at index n in a[],
    (t, v, n) =>     //   with t as the accumulator:
    t +              //     add to t ...
    v * (            //     ... v multiplied by S(n, k)
                     //     actually implemented as s(n) where s is ...
      s = n =>       //     ... a recursive function taking only n explicitly:
      n ?            //       if n is not 0:
        s(--n, k--)  //         compute S(n - 1, k - 1)
        + ++k * s(n) //         + k * S(n - 1, k)
      :              //       else:
        !k           //         return 1 if k = 0, or 0 otherwise
    )(n),            //     initial call to S
    0                //     start with t = 0
  )                  //   end of reduce()
)                    // end of map()
typo
Source Link
Arnauld
  • 205.4k
  • 21
  • 186
  • 670
a =>               // a[] = coefficients in ascending order
a.map((_, k) =>    // for each coefficient at index k in a[]:
  a.reduce(        //   for each coefficient v at index n in a[],
    (t, v, n) =>   //   with t as the accumulator:
    t +            //     add to t ...
    v * (          //     ... v multiplied by S(n, k)
                   //     actually implemented as S(k) where S is ...
      S = k =>     //     ... a recursive function taking only k explicitly:
      n ?          //       if n is not 0:
        --n        //         decrement n
        + k * S(k) //         compute k * S(k)
        + S(k - 1) //         + S(k - 1)
        - n++      //         restore n (and cancelscancel out the earlier --n)
      :            //       else:
        !k         //         return 1 if k = 0, or 0 otherwise
    )(k),          //     initial call to S
    0              //     start with t = 0
  )                //   end of reduce()
)                  // end of map()
a =>               // a[] = coefficients in ascending order
a.map((_, k) =>    // for each coefficient at index k in a[]:
  a.reduce(        //   for each coefficient v at index n in a[],
    (t, v, n) =>   //   with t as the accumulator:
    t +            //     add to t ...
    v * (          //     ... v multiplied by S(n, k)
                   //     actually implemented as S(k) where S is ...
      S = k =>     //     ... a recursive function taking only k explicitly:
      n ?          //       if n is not 0:
        --n        //         decrement n
        + k * S(k) //         compute k * S(k)
        + S(k - 1) //         + S(k - 1)
        - n++      //         restore n (and cancels out the earlier --n)
      :            //       else:
        !k         //         return 1 if k = 0, or 0 otherwise
    )(k),          //     initial call to S
    0              //     start with t = 0
  )                //   end of reduce()
)                  // end of map()
a =>               // a[] = coefficients in ascending order
a.map((_, k) =>    // for each coefficient at index k in a[]:
  a.reduce(        //   for each coefficient v at index n in a[],
    (t, v, n) =>   //   with t as the accumulator:
    t +            //     add to t ...
    v * (          //     ... v multiplied by S(n, k)
                   //     actually implemented as S(k) where S is ...
      S = k =>     //     ... a recursive function taking only k explicitly:
      n ?          //       if n is not 0:
        --n        //         decrement n
        + k * S(k) //         compute k * S(k)
        + S(k - 1) //         + S(k - 1)
        - n++      //         restore n (and cancel out the earlier --n)
      :            //       else:
        !k         //         return 1 if k = 0, or 0 otherwise
    )(k),          //     initial call to S
    0              //     start with t = 0
  )                //   end of reduce()
)                  // end of map()
minor clarification
Source Link
Arnauld
  • 205.4k
  • 21
  • 186
  • 670
Loading
saved 1 byte
Source Link
Arnauld
  • 205.4k
  • 21
  • 186
  • 670
Loading
added a commented version
Source Link
Arnauld
  • 205.4k
  • 21
  • 186
  • 670
Loading
minor clarification
Source Link
Arnauld
  • 205.4k
  • 21
  • 186
  • 670
Loading
saved 8 bytes
Source Link
Arnauld
  • 205.4k
  • 21
  • 186
  • 670
Loading
added an explanation
Source Link
Arnauld
  • 205.4k
  • 21
  • 186
  • 670
Loading
Source Link
Arnauld
  • 205.4k
  • 21
  • 186
  • 670
Loading